Class: Move

Inherits:
Object
  • Object
show all
Defined in:
lib/software_challenge_client/move.rb

Overview

A move that can be performed in Mississippi Queen. A move consists of multiple actions in a specific order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actions = [], hints = []) ⇒ Move

Initializer



20
21
22
23
# File 'lib/software_challenge_client/move.rb', line 20

def initialize(actions = [], hints = [])
  @actions = actions
  @hints = hints
end

Instance Attribute Details

#actionsArray<Action> (readonly)

Returns List of actions which should be performed in this move in the order determined by the array order.

Returns:

  • (Array<Action>)

    List of actions which should be performed in this move in the order determined by the array order.



12
13
14
# File 'lib/software_challenge_client/move.rb', line 12

def actions
  @actions
end

#hintsArray<DebugHint> (readonly)

Returns the move’s hints.

Returns:



16
17
18
# File 'lib/software_challenge_client/move.rb', line 16

def hints
  @hints
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
# File 'lib/software_challenge_client/move.rb', line 31

def ==(other)
  actions.size == other.actions.size &&
    actions.zip(other.actions).map { |a, b| a == b }.all?
end

#add_action(action) ⇒ Object



40
41
42
# File 'lib/software_challenge_client/move.rb', line 40

def add_action(action)
  @actions << action
end

#add_action_with_order(action, index) ⇒ Object



44
45
46
# File 'lib/software_challenge_client/move.rb', line 44

def add_action_with_order(action, index)
  @actions[index] = action
end

#add_hint(hint) ⇒ Object

adds a hint to the move

Parameters:



27
28
29
# File 'lib/software_challenge_client/move.rb', line 27

def add_hint(hint)
  @hints.push(hint)
end

#perform!(gamestate) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/software_challenge_client/move.rb', line 48

def perform!(gamestate)
  raise InvalidMoveException.new(
      "Zug enthält keine Aktionen (zum Aussetzen die Aktion Skip benutzen).",
      self) if @actions.empty?
  @actions.each do |action|
    action.perform!(gamestate)
  end
  raise InvalidMoveException.new(
    'Es muss eine Karte gespielt werden.',
    self) if gamestate.current_player.must_play_card
  # change the state to the next turn
  gamestate.last_move = self
  gamestate.turn += 1
  gamestate.switch_current_player
  # change carrots for next player if on first/second-position-field
  if gamestate.current_field.type == FieldType::POSITION_1 && gamestate.is_first(gamestate.current_player)
    gamestate.current_player.carrots += 10
  end
  if gamestate.current_field.type == FieldType::POSITION_2 && gamestate.is_second(gamestate.current_player)
    gamestate.current_player.carrots += 30
  end
end

#to_sObject



36
37
38
# File 'lib/software_challenge_client/move.rb', line 36

def to_s
  "Move: #{actions}"
end