The framework and documentation is provided here: https://github.com/SebLague/Chess-Challenge
I forked it and it ran with no issues in my already installed copy of Visual Studio and opened a nice simplistic GUI. If you want to take part in the challenge you have to write your own bot using his API under a fun constraint: The Bot Brain Capacity may not exceed 1024!
He explains all that in his video and on github but basically the code you submit is converted into an abstract syntax tree and then the amount of tokens are counted. I think it makes a much better constraint than counting characters or measuring the compile size
I found it incredibly easy to get started. After ~20 minutes I had negamax implemented using the provided API in a few lines of code:
Code: Select all
using ChessChallenge.API;
public class SimpleNegaMax : IChessBot
{
//Implements the https://en.wikipedia.org/wiki/Negamax algorithm
// Piece values: null, pawn, knight, bishop, rook, queen
int[] PieceValues = { 0, 100, 300, 300, 500, 900 };
int CheckmateScore = 9999;
int Depth = 4;
public Move Think(Board board, Timer timer)
{
Move bestMove = default;
int bestScore = -CheckmateScore;
foreach (Move move in board.GetLegalMoves())
{
board.MakeMove(move);
int score = -NegaMax(1, board);
board.UndoMove(move);
if (score > bestScore)
{
bestMove = move;
bestScore = score;
}
}
return bestMove;
}
private int NegaMax(int depth, Board board)
{
if (depth == Depth)
return Eval(board);
if (board.IsInCheckmate())
return -CheckmateScore;
int bestScore = -CheckmateScore;
foreach (Move move in board.GetLegalMoves())
{
board.MakeMove(move);
int score = -NegaMax(depth + 1, board);
board.UndoMove(move);
if (score > bestScore)
bestScore = score;
}
return bestScore;
}
private int Eval(Board board)
{
int eval = 0;
for (int pieceType = 1; pieceType < 5; pieceType++)
{
var white = board.GetPieceList((PieceType)pieceType, true);
var black = board.GetPieceList((PieceType)pieceType, false);
eval += (white.Count - black.Count) * PieceValues[pieceType];
}
return board.IsWhiteToMove ? eval : -eval;
}
}
The above code translates into 227 of 1024 available Brain Capacity. So you can implement a somewhat sophisticated search *but* if I try to copy some basic PSTs in there (2*6*64) that will exceed the available brain power already. This means the "normal" approach to encode the evaluation in a bazillion of "weights" is not viable and that's effectively preventing most of the existing engine from being ported as a bot.
Sounds fun? I might share a few more simple bots to make it easier for the non C# programmers to get started. The code above doesn't need any explanation, right? But if you've got questions I'm sure the C# coders around here will be eager to help. (Me included, but I'm on vacaton in the next 2 weeks)