int PositionEvalueation = 0;
Move FirstDepth;
Move SecondDepth;
foreach (Move move in FirstDepthMoves)
{
//Try a move
board.MakeMove(move);
Move[] SecondDepthMoves = board.GetLegalMoves();
foreach (Move move1 in SecondDepthMoves)
{
// Try a second move
board.MakeMove(move1);
int CurrentEvaluation1 = EvaluatePosition(board, !IsBotWhite);
// If move be good, then we memorize it
if (CurrentEvaluation1 > PositionEvalueation)
{
//Record this to then play + for seeing its thinking procces in Console
FirstDepth = move;
SecondDepth = move1;
PositionEvalueation = CurrentEvaluation1;
}
board.UndoMove(move1);
}
board.UndoMove(move);
}
// Here it tells me that It didnt get the value assigned to FirstDepth and SecondDepth from foreach loop
//Idk what to do else about it
Console.WriteLine(FirstDepth);
board.MakeMove(FirstDepth);
Console.WriteLine(EvaluatePosition(board, !IsBotWhite));
Console.WriteLine(SecondDepth);
board.MakeMove(SecondDepth);
Console.WriteLine(EvaluatePosition(board, !IsBotWhite));
board.UndoMove(SecondDepth);
board.UndoMove(FirstDepth);
在上述法典中,我宣布每 lo前的变数,而每 lo的变数则按预期价值计算。 但在那里,我试图写这封信,以便赶上这段话,并与它一道行动,却告诉我,这是没有签名的。
我曾试图为其面前的变数确定价值,但仅仅保留这一价值而没有改变:
Move FirstDepth = moveToPlay; Move SecondDepth = moveToPlay;
我也试图设定一种临时价值,以获得这一价值,但也做了一些工作。
For more context, this is part of my attempt at a tiny chess bot contest which was created by SebLeague. Here is a link to it: https://github.com/SebLague/Chess-Challenge Here is full file of MyBot:
using ChessChallenge.API;
using System;
public class MyBot : IChessBot
{
const PieceType Pawn = (PieceType)1;
const PieceType Knight = (PieceType)2;
const PieceType Bishop = (PieceType)3;
const PieceType Rook = (PieceType)4;
const PieceType Queen = (PieceType)5;
public Move Think(Board board, Timer timer)
{
bool IsBotWhite = board.IsWhiteToMove;
Move[] FirstDepthMoves = board.GetLegalMoves();
Random rng = new();
Move moveToPlay = FirstDepthMoves[rng.Next(FirstDepthMoves.Length)];
int PositionEvalueation = 0;
Move FirstDepth = moveToPlay;
Move SecondDepth = moveToPlay;
foreach (Move move in FirstDepthMoves)
{
//Try a move
board.MakeMove(move);
FirstDepth = moveToPlay;
SecondDepth = moveToPlay;
Move[] SecondDepthMoves = board.GetLegalMoves();
foreach (Move move1 in SecondDepthMoves)
{
// Try a second move
board.MakeMove(move1);
int CurrentEvaluation1 = EvaluatePosition(board, !IsBotWhite);
// If move be good, then we memorize it
if (CurrentEvaluation1 > PositionEvalueation)
{
//Record this to then play + for seeing its thinking procces in Console
FirstDepth = move;
SecondDepth = move1;
PositionEvalueation = CurrentEvaluation1;
}
board.UndoMove(move1);
}
board.UndoMove(move);
}
// Here it tells me that It didnt get the value assigned to FirstDepth and SecondDepth from foreach loop
//Idk what to do else about it
Console.WriteLine(FirstDepth);
board.MakeMove(FirstDepth);
Console.WriteLine(EvaluatePosition(board, !IsBotWhite));
Console.WriteLine(SecondDepth);
board.MakeMove(SecondDepth);
Console.WriteLine(EvaluatePosition(board, !IsBotWhite));
board.UndoMove(SecondDepth);
board.UndoMove(FirstDepth);
return FirstDepth;
}
int EvaluatePosition(Board board, bool IsWhite)
{
//the E stands for Enemy
PieceList Pawns = board.GetPieceList(pieceType: Pawn, white: IsWhite);
PieceList Knights = board.GetPieceList(pieceType: Knight, white: IsWhite);
PieceList Bishops = board.GetPieceList(pieceType: Bishop, white: IsWhite);
PieceList Rooks = board.GetPieceList(pieceType: Rook, white: IsWhite);
PieceList Queens = board.GetPieceList(pieceType: Queen, white: IsWhite);
bool IsWhiteE = !IsWhite;
PieceList PawnsE = board.GetPieceList(pieceType: Pawn, white: IsWhiteE);
PieceList KnightsE = board.GetPieceList(pieceType: Knight, white: IsWhiteE);
PieceList BishopsE = board.GetPieceList(pieceType: Bishop, white: IsWhiteE);
PieceList RooksE = board.GetPieceList(pieceType: Rook, white: IsWhiteE);
PieceList QueensE = board.GetPieceList(pieceType: Queen, white: IsWhiteE);
int TotalEval = ((Pawns.Count * 1) + (Knights.Count * 3) + (Bishops.Count * 3) + (Rooks.Count * 5) + (Queens.Count * 9)) - ((PawnsE.Count * 1) + (KnightsE.Count * 3) + (BishopsE.Count * 3) + (RooksE.Count * 5) + (QueensE.Count * 9));
if (board.IsDraw())
{
TotalEval = -100;
}
else if (board.IsInCheckmate())
{
TotalEval = 100;
}
if (board.IsInCheck())
{
TotalEval = TotalEval + 1;
}
return -TotalEval;
}
}