From e841481c719e2631dad3085285356c306613fa19 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Sun, 15 Jun 2008 02:19:07 +0100 Subject: [PATCH] Add direction method to Shogi::State. --- lib/games/shogi/state.rb | 4 ++++ test/games/shogi/test_shogi_state.rb | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/games/shogi/state.rb b/lib/games/shogi/state.rb index 418c6d9..4370a8d 100644 --- a/lib/games/shogi/state.rb +++ b/lib/games/shogi/state.rb @@ -47,5 +47,9 @@ module Shogi def opposite_color(color) color == :black ? :white : :black end + + def direction(color) + Point.new(0, color == :black ? -1 : 1) + end end end diff --git a/test/games/shogi/test_shogi_state.rb b/test/games/shogi/test_shogi_state.rb index 7efe0de..102d0d0 100644 --- a/test/games/shogi/test_shogi_state.rb +++ b/test/games/shogi/test_shogi_state.rb @@ -46,4 +46,9 @@ class TestShogiState < Test::Unit::TestCase assert_equal :white, @state.opposite_color(:black) assert_equal :black, @state.opposite_color(:white) end + + def test_direction + assert_equal Point.new(0, -1), @state.direction(:black) + assert_equal Point.new(0, 1), @state.direction(:white) + end end -- 2.11.4.GIT