private void SetupPosition(string[] args) { var positionType = args[1]; ChessPosition position; switch (positionType) { case "startpos": position = ChessPosition.FromFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 "); break; case "fen": position = ChessPosition.FromFEN(args[2], args[3], args[4]); break; default: return; } game.Add(new GameState(position, new ChessMove(0))); int movesIndex; for (movesIndex = 2; movesIndex < args.Length; movesIndex++) { if (args[movesIndex] == "moves") { break; } } for (int i = movesIndex + 1; i < args.Length; i++) { ChessMove move = ChessMove.Parse(args[i]); position = position.ApplyMove(move); game.Add(new GameState(position, move)); } }
internal GameState(ChessPosition p, ChessMove m) { Position = p; Move = m; }
internal static float[] Evaluate(ChessPosition position) => Evaluate(new ChessPosition[] { position })[0];
internal static ChessPosition FromFEN(string boardfen, string turn, string castling) { var position = new ChessPosition { whiteToMove = (turn == "w"), board = Board.FromFen(boardfen), enPassantSquare = new Square(64), }; foreach (char c in castling) { switch (c) { case 'K': case 'Q': for (Square ws = new Square(0); ws.binary < 8; ws.binary++) { if (position.GetPiece(ws) == 'R') { if (position.whiteOOO == null) { position.whiteOOO = ws.File; } else { position.whiteOO = ws.File; } } } break; case 'k': case 'q': for (Square bs = new Square(64 - 8); bs.binary < 64; bs.binary++) { if (position.GetPiece(bs) == 'r') { if (position.blackOOO == null) { position.blackOOO = bs.File; } else { position.blackOO = bs.File; } } } break; default: if (c >= 'A' && c <= 'H') { if (position.whiteOOO == null) { position.whiteOOO = c - 'A'; } else { position.whiteOO = c - 'A'; } } else if (c >= 'a' && c <= 'h') { if (position.blackOOO == null) { position.blackOOO = c - 'a'; } else { position.blackOO = c - 'a'; } } break; } } return(position); }