Class: Berlin::AI::Game

Inherits:
Object
  • Object
show all
Includes:
Internal
Defined in:
lib/ai/game.rb,
lib/ai/game_internal.rb

Overview

Game keeps track of current games played by the server, indexing them on their uniq id.

Defined Under Namespace

Modules: Internal

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Internal

included, #reset!, #update

Instance Attribute Details

#current_turnObject

Returns the value of attribute current_turn.



7
8
9
# File 'lib/ai/game.rb', line 7

def current_turn
  @current_turn
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/ai/game.rb', line 7

def id
  @id
end

#mapObject

Returns the value of attribute map.



7
8
9
# File 'lib/ai/game.rb', line 7

def map
  @map
end

#maximum_number_of_turnsObject

Returns the value of attribute maximum_number_of_turns.



7
8
9
# File 'lib/ai/game.rb', line 7

def maximum_number_of_turns
  @maximum_number_of_turns
end

#movesObject

Returns the value of attribute moves.



7
8
9
# File 'lib/ai/game.rb', line 7

def moves
  @moves
end

#number_of_playersObject

Returns the value of attribute number_of_players.



7
8
9
# File 'lib/ai/game.rb', line 7

def number_of_players
  @number_of_players
end

#player_idObject

Returns the value of attribute player_id.



7
8
9
# File 'lib/ai/game.rb', line 7

def player_id
  @player_id
end

#time_limit_per_turnObject

Returns the value of attribute time_limit_per_turn.



7
8
9
# File 'lib/ai/game.rb', line 7

def time_limit_per_turn
  @time_limit_per_turn
end

#turns_leftObject

Returns the value of attribute turns_left.



7
8
9
# File 'lib/ai/game.rb', line 7

def turns_left
  @turns_left
end

Instance Method Details

#add_move(from, to, number_of_soldiers) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/ai/game.rb', line 10

def add_move(from, to, number_of_soldiers)     
  # remove moving soldiers from from node
  from.available_soldiers -= number_of_soldiers

  # adding incoming soldiers to next node
  to.incoming_soldiers += number_of_soldiers

  # add move
  @moves << {:from => from.to_i, :to => to.to_i, :number_of_soldiers => number_of_soldiers.to_i}
end