Skip to content

Commit

Permalink
"Finished" updating the attack graph whenever a move is observed.
Browse files Browse the repository at this point in the history
Now, write unit tests and then optimize your code.
  • Loading branch information
skytreader committed Nov 10, 2014
1 parent 5f3df8f commit 797dabf
Showing 1 changed file with 17 additions and 2 deletions.
Expand Up @@ -150,9 +150,8 @@ public void update(Observable o, Object arg){
/*
Get the terminal square of the move and add it to its new attackers
*/
Set<Point> piecePos = observedBoard.getPiecePositions();
try{
Set<Point> piecePos = observedBoard.getPiecePositions();

for(Point pos : piecePos){
ChessPiece cp = observedBoard.getPieceAt(pos.x, pos.y);
Set<Point> moves = cp.getMoves(pos.x, pos.y, observedBoard);
Expand All @@ -169,6 +168,22 @@ public void update(Observable o, Object arg){
/*
Finally, note the pieces the moved piece attacks in its new position
*/
try{
ChessPiece movedPiece = observedBoard.getPieceAt(moveDesc[1].x,
moveDesc[1].y);
Set<Point> movedPieceMoves = movedPiece.getMoves(moveDesc[1].x,
moveDesc[1].y, observedBoard);
for(Point pos : piecePos){
if(movedPieceMoves.contains(pos)){
updateAttackGraph(moveDesc[1], pos);
}
}
} catch(NotMeException nme){
// TODO Maybe, merge this with the try-catch block above since
// I'd have the same comments on this one. Maybe even just do
// everything in one loop.
nme.printStackTrace();
}
}
}
}

0 comments on commit 797dabf

Please sign in to comment.