Apr
14
Posted on 14-04-2009
Filed Under (Programming Hints, School Work) by Steven on 14-04-2009

So today I passed off my chess project in my Computer Science CS 240 class.  I think I finished in a fairly good amount of time.  Only stayed up late one night working on it.  My code isn’t super effective in all aspects, although I did manage to do a few things that helped me simplify things.

  • I used an external XML parser called CMarkup, it is free for non-commercial use and it handles all of the silly cases the TA’s give us just fine (just remember to xml.ResetMainPos(); after parsing the board so it can still parse the history even if it came before the board in the xml file.
  • I only wrote two GetCandidateMoves functions.  One for my Piece class and one for the Pawn class.  I just defined directions for each piece, and the main piece move method just got squares in each direction until piece was found or it went off the board.  The pawn class was special just because it had special cases for the first move and capturing moves
  • I wrote a couple of methods in my main Game class that checked for Check and Checkmate (which also shared some child methods).  Stalemate was simply when it is Checkmate but not Check (with the way I wrote those methods).
  • I had memory issues until I took all pointers out of the MoveHistory.  I ended up just saving the piece type and color in the move history instead of a pointer to the piece.  I had issues leaking memory since sometimes I was putting pointers from the pieces saved in the Board class in the MoveHistory then other times I was putting pointers from the Board class in the MoveHistory.  So, so pointers in the move history.  And I made the board basically be the holder for all of the active piece pointers.  When a piece was captured or created, that is when I called delete or new. ( And the board destructor would clean-up any pieces left on the board when exiting or deleting the board before loading a new file).

Another project done for Steven Hansen, and now I am done with a CS minor and a EE major.

    (2) Comments    Read More   

    Comments

    [...] cs240 Chess Project BYU — 3:48pm via Steven Hansen Weblog posted under updates blog comments powered by [...]


    [...] cs240 Chess Project BYU — 8:48pm via Steven Hansen Weblog posted under updates blog comments powered by [...]


    Post a Comment
    Name:
    Email:
    Website:
    Comments: