long PerftCount(int depth) { Depth = depth; Results = new PerftResults(); Results.StartDepth = Depth; return(PerftCount(Board.Copy(), Depth)); }
/// <summary> /// Figures out if the specified move puts or keeps your own king in check, which is illegal /// </summary> /// <param name="board"></param> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public bool MoveSelfChecks(int from, int to) { Board board = this; Color colorToMove = board.GetColor(from); board = board.Copy(); board.Move(from, to, false); bool ok = board.IsChecked(colorToMove); return(ok); }
private long PerftCount(Board boardBase, int depth) { long total = 0; // find all the moves var moves = Moves.GetMoves(boardBase); for (int i = 0; i < moves.Length; i++) { Move move = moves[i]; var board = boardBase.Copy(); bool valid = board.Move(move.From, move.To, true); if (!valid) { continue; } if (move.Promotion > 0) { board.Promote(move.To, move.Promotion); } long cnt = (depth == 1) ? 1 : PerftCount(board, depth - 1); total += cnt; // log data in the top node if (Results.StartDepth == depth) { Results.Entries.Add(new PerftEntry() { Count = cnt, From = move.From, To = move.To }); } } if (Results.StartDepth == depth) { Results.Total = total; } return(total); }