Permalink
Browse files

setup both white and red teams

  • Loading branch information...
1 parent 6332c79 commit a4fa8ce6f10a72507f3e8f022c40353113ec20e6 @mspwong committed Aug 28, 2011
Showing with 16 additions and 13 deletions.
  1. +7 −5 game.rb
  2. +9 −8 game_spec.rb
View
12 game.rb
@@ -2,12 +2,14 @@ class Game
attr_accessor :teams
def initialize
- pieces = (1..12).to_a
@teams = Hash.new
- ["red", "white"].each do |name|
- @teams[name] = {}
- [[1,1],[3,1],[5,1],[7,1],[2,2],[4,2],[6,2],[8,2],[1,3],[3,3],[5,3],[7,3]].each_with_index do |coordinates, index|
- @teams[name][index+1] = {:x=>coordinates.first, :y=>coordinates.last}
+ setup = {}
+ setup["white"] = [[1,1],[3,1],[5,1],[7,1],[2,2],[4,2],[6,2],[8,2],[1,3],[3,3],[5,3],[7,3]]
+ setup["red"] = [[2,6],[4,6],[6,6],[8,6],[1,7],[3,7],[5,7],[7,7],[2,8],[4,8],[6,8],[8,8]]
+ setup.each do |key, value|
+ @teams[key] = {}
+ value.each_with_index do |coordinates, index|
+ @teams[key][index+1] = {:x=>coordinates.first, :y=>coordinates.last}
end
end
end
View
@@ -36,14 +36,15 @@
true
end
end.should eq true
-
- #[[1,1],[3,1],[5,1],[7,1],[2,2],[4,2],[6,2],[8,2],[1,3],[3,3],[5,3],[7,3]].each do |coordinates|
- # assert pieces.any? { |p| p.team_id == teams(:white).id && p.x == coordinates[0] && p.y == coordinates[1] }
- #end
- #
- #[[2,6],[4,6],[6,6],[8,6],[1,7],[3,7],[5,7],[7,7],[2,8],[4,8],[6,8],[8,8]].each do |coordinates|
- #assert pieces.any? { |p| p.team_id == teams(:red).id && p.x == coordinates[0] && p.y == coordinates[1] }
- #end
+ @game.teams["red"].flatten.all? do |piece|
+ if piece.class == Hash
+ [[2,6],[4,6],[6,6],[8,6],[1,7],[3,7],[5,7],[7,7],[2,8],[4,8],[6,8],[8,8]].any? do |coordinates|
+ piece == {:x => coordinates.first, :y => coordinates.last}
+ end
+ else
+ true
+ end
+ end.should eq true
end
end

0 comments on commit a4fa8ce

Please sign in to comment.