Thursday, February 27, 2014

A Chess Project, Part 6

Intro

Here in part 6 we won't go very in-depth into the code. There were just too many changes, so I'll post a link to the full solution at the bottom of this post for you to download and peruse at your pleasure. I'll cover some of the highlights below though so you know what's different from last week.

ChessValidMoveCalculator

A number of files have been modified to make this week possible. First and foremost, ChessValidMoveCalculator. It has been very heavily modified to include the following types of chess piece movement:
  1. basic knight moves
  2. basic bishop moves
  3. basic rook moves
  4. basic queen moves
  5. basic king moves
  6. can't move a piece on top of another piece of the same color
  7. only the person whose turn it is can move
  8. pawns can't jump over pieces
  9. knights CAN jump over pieces
  10. bishops can't jump over pieces
  11. rooks can't jump over pieces
  12. queens can't jump over pieces
  13. pawns can go 2 squares only if they start on row1 or row7
  14. pawns can move diagonal only to capture piece
And I also refactored some code and weeded out a couple bugs in this unit. Have a look, you'll see this unit is starting to look pretty close to complete (at least until we code in victory conditions).

Default.aspx and Default.aspx.cs In BlogChessApiFlexer

I modified these pages only to facilitate testing of the Web API. But hey, it's still useful!

BlogChessController (the Web API Main Unit)

I also modified this unit to facilitate testing. The method PostBestMove, which is supposed to calculate and return the best move, has now been tasked with calculating and returning the complete list of valid moves. Later on when we can evaluate boards we'll set it back to its rightful purpose, but for now it's a great way to debug the code that's currently available.

Action Shot

I kinda feel like I need to show this product in action, so here's a screenshot of it doing it's thing:

The above shows the valid moves, as calculated by our code, assuming a standard chess starting position. Recall those piece values from a couple blogs ago? 0=empty square,1=pawn,2=knight,3=bishop,4=rook,5=queen,6=king, with black pieces being the negative value. Pretty cool huh? I hope you're enjoying this project, I certainly am. Lotta work though!

What's Next?

We still haven't attempted victory conditions, so we'll still have to do those at some point. We also skipped 2 types of movement that I just didn't have time for this week: pawn capture en-passant, and castling. We'll probably tackle at least those 2 next week.

And as promised, here is the solution file.

No comments:

Post a Comment