//считает количество фигур на поле private static void NumberPiece(IBoard board, out int whiteKings, out int blackKings, out int whiteMen, out int blackMen) { whiteKings = 0; blackKings = 0; whiteMen = 0; blackMen = 0; for (int pos = 1; pos <= BoardConstants.LightSquareCount; pos++) { Piece piece = board[pos]; if (BoardUtilities.IsPiece(piece)) { switch (piece) { case Piece.BlackMan: blackMen++; break; case Piece.WhiteMan: whiteMen++; break; case Piece.BlackKing: blackKings++; break; case Piece.WhiteKing: whiteKings++; break; } } } }
/// <summary> /// CanJump - Может прыгать /// Check the player jump any pieces on the board /// Проверьте игрока, прыгайте любые фигуры на доске /// </summary> /// <param name="board"> /// the board state /// состояние правления /// </param> /// <param name="player"> /// the player with the turn /// игрок с терном /// </param> /// <returns><code>true</code> /// if the player can make a jump /// если игрок может сделать прыжок /// </returns> static bool CanJump(IBoard board, Player player) { for (int row = 0; row < board.Rows; row++) { for (int col = 0; col < board.Cols; col++) { if (BoardUtilities.IsPiece(board[row, col]) && (BoardUtilities.GetPlayer(board[row, col]) == player) && CanJump(board, row, col) ) { return(true); } } } return(false); }
/// <summary> /// CanJump - Может прыгать /// Check if piece at position can jump /// Проверьте, может ли кусок в положении прыгать /// </summary> /// <param name="board"> /// the board state /// состояние правления /// </param> /// <param name="row"> /// the row the piece is on /// строка, на которой стоит произведение /// </param> /// <param name="col"> /// the column the piece is on /// колонка, на которой находится произведение /// </param> /// <returns><code>true</code> /// if the piece can jump /// если кусок может прыгать /// </returns> static bool CanJump(IBoard board, int row, int col) { Piece piece = board[row, col]; if (!BoardUtilities.IsPiece(piece)) { return(false); } int forwardDirection = (BoardUtilities.IsBlack(piece)) ? 1 : -1; int backwardDirection = (!BoardUtilities.IsKing(piece)) ? 0 : (BoardUtilities.IsBlack(piece)) ? -1 : 1; return(CanJump(board, row, col, forwardDirection, -1) || CanJump(board, row, col, forwardDirection, 1) || (backwardDirection != 0 && ( CanJump(board, row, col, backwardDirection, -1) || CanJump(board, row, col, backwardDirection, 1) ) )); }
/// <summary> /// HasMovesAvailable - Есть фильмы в наличии /// Check if the player has any more moves /// Проверьте, есть ли у игрока больше ходов /// </summary> /// <param name="board"> /// the state of the board /// состояние правления /// </param> /// <param name="player"> /// the player with the turn /// игрок с терном /// </param> /// <returns><code>true</code> /// if the player can make a move /// если игрок может сделать ход /// </returns> public static bool HasMovesAvailable(IBoard board, Player player) { for (int row = 0; row < board.Rows; row++) { for (int col = 0; col < board.Cols; col++) { if (BoardUtilities.IsPiece(board[row, col]) && (player == BoardUtilities.GetPlayer(board[row, col]))) { if (CanWalk(board, row, col)) { return(true); } else if (CanJump(board, row, col)) { return(true); } } } } return(false); }
private static int Evaluate(IBoard board, Player player) { const int MAN_WEIGHT = 100; const int KING_WEIGHT = 130; const int BACKRANK_WEIGHT = 10; int score = 0; int whiteKings = 0, blackKings = 0, whiteMen = 0, blackMen = 0; for (int pos = 1; pos < BoardConstants.LightSquareCount; pos++) { Piece piece = board[pos]; if (BoardUtilities.IsPiece(piece)) { switch (piece) { case Piece.BlackMan: blackMen++; break; case Piece.WhiteMan: whiteMen++; break; case Piece.BlackKing: blackKings++; break; case Piece.WhiteKing: whiteKings++; break; } } } if (blackMen + blackKings == 0) { whiteKings += 100;; } else if (whiteMen + whiteKings == 0) { blackKings += 100; } if (board[31] == Piece.WhiteMan && board[30] == Piece.WhiteMan && blackMen > 1) { score -= BACKRANK_WEIGHT; } if (board[1] == Piece.BlackMan && board[3] == Piece.BlackMan && whiteMen > 1) { score += BACKRANK_WEIGHT; } int blackPieceScore = blackKings * KING_WEIGHT + blackMen * MAN_WEIGHT; int whitePieceScore = whiteKings * KING_WEIGHT + whiteMen * MAN_WEIGHT; score += ((blackPieceScore - whitePieceScore) * 200) / (blackPieceScore + whitePieceScore); score += blackPieceScore - whitePieceScore; //int blackPieceScore = blackKings * 4 + blackMen * 1; //int whitePieceScore = whiteKings * 4 + whiteMen * 1; //score = blackPieceScore - whitePieceScore; const int RANDOMIZER_MIN = -10; const int RANDOMIZER_MAX = 10; return(((player == Player.Black) ? score : -score) + random.Next(RANDOMIZER_MIN, RANDOMIZER_MAX)); }
private void Paint(Graphics g, IBoard board, int squareSize, FloatingPiece floatingPiece, bool paintBoard, bool paintPiece) { int x = 0; int y = 0; int imageSize = squareSize - imageInset * 2; int position = BoardConstants.LightSquareCount; for (int row = 0; row < BoardConstants.Rows; row++) { x = 0; for (int col = 0; col < BoardConstants.Rows; col++) { bool isDarkSquare = (row % 2 != col % 2); // // Draw square // if (paintBoard) { g.DrawImage(GetSquareImage(isDarkSquare), x, y, squareSize, squareSize); } if (isDarkSquare) { // // Draw square number // if (paintBoard) { g.DrawString(position.ToString(CultureInfo.CurrentCulture), positionFont, positionBrush, x, y); } // // Draw piece on square // if (paintPiece) { Piece piece = board[position]; if ((piece != Piece.None) && (floatingPiece.Position != position)) { g.DrawImage(GetPieceImage(piece), x + imageInset, y + imageInset, imageSize, imageSize); } } position--; } x += squareSize; } y += squareSize; } // // draw floating piece // if (paintPiece) { if ((floatingPiece.Active) && (BoardUtilities.IsPiece(board[floatingPiece.Position]))) { int floatingPieceSize = (int)(imageSize * 1.2); const int shadowOffset = 6; Image floatingPieceImage = GetPieceImage(board[floatingPiece.Position]); g.FillEllipse(shadowBrush, floatingPiece.X + shadowOffset, floatingPiece.Y + shadowOffset, floatingPieceSize, floatingPieceSize); g.DrawImage(floatingPieceImage, floatingPiece.X + imageInset, floatingPiece.Y + imageInset, floatingPieceSize, floatingPieceSize); } } }