theFirehoseProject/chess — pull request #24 by bobbyali (2014-12-15 00:32:22+00:00)
Title: Added pawn move logic in Game model, and test

I wrote some code in the Game model that tests whether a pawn move is valid, and an accompanying test for it using FactoryGirl.

The new "self.is_move_allowed? function in Game.rb first calls a helper function, one per piece type (I wrote one for pawns called "legit_moves_for_pawn"), which returns an array of x/y coordinates that a specific piece (in this case a pawn) can move to. (This could also be used to generate a list of highlighted squares indicating possible target destinations for a piece.) The "is_move_allowed?" function then tests whether the new [x, y] destination coordinates that the player has selected are within that returned array of valid coordinates.

Hopefully this is a good template for writing the piece move logic for other pieces. Thoughts?