Permalink
Browse files

Changed Footsteps so that it doesn't use Board and keeps a more detai…

…led bid

history.  This version (2.5.0) is move compatible with the last version, but
bots, etc, will have to be updated.
  • Loading branch information...
1 parent e3348e9 commit 85e069552f7a6a095cbaec39dab7cec7fd0f3fe5 @eki committed Mar 5, 2009
Showing with 32 additions and 29 deletions.
  1. +26 −25 lib/vying/rules/misc/footsteps.rb
  2. +6 −4 test/vying/rules/misc/footsteps_test.rb
@@ -5,22 +5,22 @@
Rules.create( "Footsteps" ) do
name "Footsteps"
- version "2.0.0"
+ version "2.5.0"
players :left, :right
- winner_direction :left => :w, :right => :e
+ direction :left => -1, :right => 1
+ winner :left => 0, :right => 6
position do
- attr_reader :board, :points, :bids, :bid_history
+ attr_reader :points, :bids, :bid_history, :marker
def init
- @board = Board.rect( 7, 1 )
- @board[:d1] = :white
+ @marker = 3
- @points = { :left => 50, :right => 50 }
- @bids = { :left => nil, :right => nil }
- @bid_history = { :left => [], :right => [] }
+ @points = { :left => 50, :right => 50 }
+ @bids = { :left => nil, :right => nil }
+ @bid_history = []
end
def has_moves
@@ -38,22 +38,28 @@ def apply!( move, player )
bids[player] = bid
- players.each { |p| bids[p] ||= 0 if points[p] == 0 }
+ players.each { |p| bids[p] ||= 0 if points[p] == 0 }
if players.all? { |p| bids[p] }
- c = board.occupied( :white ).first
+ if bids[:left] == bids[:right]
+ winner = nil
+ else
+ winner = bids[:left] > bids[:right] ? :left : :right
+ end
- max_bid = bids.values.max
- wps = players.select { |p| bids[p] == max_bid }
+ h = { :points => points.dup,
+ :bids => bids.dup,
+ :winner => winner,
+ :marker => { :from => @marker } }
- if wps.length == 1
- d = Coords::DIRECTIONS[rules.winner_direction[wps.first]]
- board.move( c, c + d )
- end
+ @marker += rules.direction[winner] if winner
+
+ h[:marker][:to] = @marker
+
+ bid_history << h
players.each do |p|
points[p] -= bids[p]
- bid_history[p] << bids[p]
bids[p] = nil
end
end
@@ -62,20 +68,15 @@ def apply!( move, player )
end
def final?
- c = board.occupied( :white ).first
- c.x == 0 || c.x == 6 ||
- (points[:left] == 0 && points[:right] == 0)
+ marker == 0 || marker == 6 || points.values.all? { |p| p == 0 }
end
def winner?( player )
- c = board.occupied( :white ).first
- (player == :left && c.x == 0) ||
- (player == :right && c.x == 6)
+ rules.winner[player] == marker
end
def draw?
- c = board.occupied( :white ).first
- c.x != 0 && c.x != 6 && points[:left] == 0 && points[:right] == 0
+ ! players.any? { |p| winner?( p ) }
end
def censor( player )
@@ -23,10 +23,12 @@ def test_players
def test_init
g = Game.new( rules )
- b = Board.rect( 7, 1 )
- b[:d1] = :white
-
- assert_equal( b, g.board )
+ assert_equal( 3, g.marker )
+ assert_equal( 50, g.points[:left] )
+ assert_equal( 50, g.points[:right] )
+ assert_equal( nil, g.bids[:left] )
+ assert_equal( nil, g.bids[:right] )
+ assert_equal( [], g.bid_history )
end
def test_has_score

0 comments on commit 85e0695

Please sign in to comment.