Commits

Steven! Ragnarök committed 69cdfcd

Save work in progress before reimplementing board.

Comments (0)

Files changed (3)

+module Piece
+  TYPES = { 'P' => Pawn, 'R' => Rook, 'N' => Knight, 'B' => Bishop,
+            'Q' => Queen, 'K' => King }
+
+  def new piece, location
+    TYPES[piece.last].new piece.first, location
+  end
+  module_function :new
+end
+

13/lib/piece/pawn.rb

+class Piece::Pawn
+ attr_reader :color, :location
+
+  def initialize color, location, board
+    @color, @location = color, location
+  end
+
+  # Returns an array with the path from location to destination or an empty
+  # array if none exists.
+  def move destination
+
+  end
+
+  # returns an array of valid destinations for this piece's move.
+  def destinations
+  end
+end

13/test/pawn_test.rb

+require 'minitest/unit'
+require 'minitest/autorun'
+require './lib/board'
+require './lib/piece/pawn'
+
+class PawnTest < MiniTest::Unit::TestCase
+
+  def setup
+    @board = Board.new <<BOARD
+bR bN bB bQ bK bB bN bR
+bP bP bP bP bP bP bP bP
+-- -- -- -- -- -- -- --
+-- -- -- -- -- -- -- --
+-- -- -- -- -- -- -- --
+-- -- -- -- -- -- -- --
+wP wP wP wP wP wP wP wP
+wR wN wB wQ wK wB wN wR
+BOARD
+
+    @white_pawn = Pawn.new 'wP', :a2
+  end
+
+  def test_pawns_move_straight_ahead
+    assert_includes @white_pawn.destinations, :a3
+  end
+end
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.