/* * Does operation to move a piece * Called on click. May or may not result in actual move * Triggers AI action if specified */ private void MovePiece(Piece p) { if (previousPiece.player.GetID() == 1 && (p.player.GetID() == 1 && p.position.X == previousPiece.position.X && p.position.Y == previousPiece.position.Y)) { clearBorders(); } else if (previousPiece.player.GetID() == 2 && (p.player.GetID() == 2 && p.position.X == previousPiece.position.X && p.position.Y == previousPiece.position.Y)) { clearBorders(); } // check if piece can move to that place else if (previousPiece.player.GetID() == 1) { //if not the right player if ((string)App.Current.Properties["ActivePlayer"] == "Black") { previousPiece = null; clearBorders(); return; } List <System.Drawing.Point> endSpaces = previousPiece.getPossibleEndSpaces(board1); System.Drawing.Point piecePosition = p.position; if (p.player.GetID() == 2) { piecePosition = new System.Drawing.Point(7 - p.position.X, 7 - p.position.Y); } if (endSpaces != null && endSpaces.Contains(piecePosition)) { // this move is allowed! Move m = new Move(previousPiece.position, piecePosition); board1.MakeMove(m); clearBorders(); UpdateBoard(board1); previousPiece = null; //AI's turn if (AI.IsChecked == true) { //wait 1 second TBI AIStep(); UpdateBoard(board1); } } else { HighlightSpots(p); } } else if (previousPiece.player.GetID() == 2) { //if not the right player if ((string)App.Current.Properties["ActivePlayer"] == "White") { previousPiece = null; clearBorders(); return; } List <System.Drawing.Point> endSpaces = previousPiece.getPossibleEndSpaces(board2); System.Drawing.Point piecePosition = p.position; if (p.player.GetID() != 2) { piecePosition = new System.Drawing.Point(7 - p.position.X, 7 - p.position.Y); } if (endSpaces != null && endSpaces.Contains(piecePosition)) { Move m = new Move(previousPiece.position, piecePosition); board2.MakeMove(m); clearBorders(); } else { HighlightSpots(p); } } else if (previousPiece.player.GetID() == 0) { HighlightSpots(p); } UpdateBoard(board1); previousPiece = null; }