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

#initializeMove

Initializer



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

def initialize
  @actions = []
  @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, current_player) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/software_challenge_client/move.rb', line 48

def perform!(gamestate, current_player)
  # check if acceleration is only first action
  other_action_before = false
  @actions.each do |a|
    if a.type != :acceleration
      other_action_before = true
    elsif other_action_before
      raise InvalidMoveException.new('Beschleunigung muss am Anfang des Zuges geschehen.', self)
    end
  end
  @actions.each { |a| a.perform!(gamestate, current_player) }
end

#to_sObject



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

def to_s
  "Move: #{actions}"
end