// ClickHandler for piece. private void Piece_Click(object sender, EventArgs e) { int[] arr; PictureBox b = (PictureBox)sender; if ((game.GetAIState() && playerColour == game.GetTurn()) || !game.GetAIState()) { if (!didChoose) { if (game.GetPiece(b.Location.Y / 57, b.Location.X / 57) != null && game.GetPiece(b.Location.Y / 57, b.Location.X / 57).GetColour() == game.GetTurn()) { srcX = b.Location.Y / 57; srcY = b.Location.X / 57; didChoose = true; // Selects the piece. this.piecesImg[srcX, srcY].Image = ImageHandler.PlaceImage(game.GetPiece(srcX, srcY).GetColour(), game.GetPiece(srcX, srcY).IsDux(), true); } } else { if (game.GetPiece(b.Location.Y / 57, b.Location.X / 57) != null && game.GetPiece(b.Location.Y / 57, b.Location.X / 57).GetColour() == game.GetTurn()) { // Reverts the previous selected piece. this.piecesImg[srcX, srcY].Image = ImageHandler.PlaceImage(game.GetPiece(srcX, srcY).GetColour(), game.GetPiece(srcX, srcY).IsDux(), false); srcX = b.Location.Y / 57; srcY = b.Location.X / 57; // Selects the piece. this.piecesImg[srcX, srcY].Image = ImageHandler.PlaceImage(game.GetPiece(srcX, srcY).GetColour(), game.GetPiece(srcX, srcY).IsDux(), true); } else if (game.GetPiece(b.Location.Y / 57, b.Location.X / 57) == null && game.UpdateBoard(srcX, srcY, b.Location.Y / 57, b.Location.X / 57)) { UpdateBoard(srcX, srcY, b.Location.Y / 57, b.Location.X / 57); didChoose = false; } } } if (game.GetTurn() == game.GetPlayerColour() * -1 && (game.GetAIState() && !didChoose)) { Application.DoEvents(); arr = AI.MakeTurn(game, 0); if (game.UpdateBoard(arr[0], arr[1], arr[2], arr[3])) { UpdateBoard(arr[0], arr[1], arr[2], arr[3]); } } }
// Gets a board an evaluates it. private static int EvaluateBoard(Board turn) { int value = 0; int playerColour = turn.GetPlayerColour(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (turn.GetPiece(i, j) != null) { if (turn.GetPiece(i, j).GetColour() == playerColour) { value--; } else { value++; } if (turn.GetPiece(i, j).IsDux()) { if (turn.GetPiece(i, j).GetColour() == playerColour) { if (turn.IsDuxStuck(i, j)) { value += 9001; } } if (turn.GetPiece(i, j).GetColour() == playerColour * -1) { if (turn.IsDuxStuck(i, j)) { value -= 1337; } } } } } } return(value); }
// Gets a board an evaluates it. private static int EvaluateBoard(Board turn) { int value = 0; int playerColour = turn.GetPlayerColour(); for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) if (turn.GetPiece(i, j) != null) { if (turn.GetPiece(i, j).GetColour() == playerColour) value--; else value++; if (turn.GetPiece(i, j).IsDux()) { if (turn.GetPiece(i, j).GetColour() == playerColour) if (turn.IsDuxStuck(i, j)) value += 9001; if (turn.GetPiece(i, j).GetColour() == playerColour * -1) if (turn.IsDuxStuck(i, j)) value -= 1337; } } return value; }