public virtual void Move(NormalMove m) { if (m.Capture!=null) Board.RemovePiece(m.To,m.Capture); Board.RemovePiece(m.From, this); Board.SetPiece(m.To,this); Moves.Add(m); }
public virtual NormalMove IsLegalMove(NormalMove normalMove, int ply) { foreach (var m in CalculateAllMoves(ply)) { if (normalMove == m) return m; } return null; }
public virtual void UndoMove(NormalMove m) { Board.RemovePiece(m.To, this); if (m.Capture != null) { Board.SetPiece(m.To,m.Capture); } Board.SetPiece(m.From,this); Moves.Remove(m); undoedMoves.Add(m); }
public override void Move(NormalMove m) { var enpassant = m as EnPassantMove; if (enpassant != null) { Moves.Add(m); Board.SetPiece(m.To,m.Piece); Board.RemovePiece(m.From,m.Piece); Board.RemovePiece(m.Capture.Square,m.Capture); } else base.Move(m); }
public int Perft(int depth,Color color, NormalMove lastmove=null) { if (depth == 0) { Log.Debug($"Came from {lastmove}"); return 0; } var clock = new Stopwatch(); clock.Start(); var allValidMoves = _board.GetAllMovesFor(color,depth).ToList(); var subMoves = 0; foreach (var move in allValidMoves) { move.Do(); subMoves+=Perft(depth-1,ColorHelper.Reverse(color),move); move.Undo(); } clock.Stop(); if (depth>4) Log.Info($"Depth {depth} took {clock.ElapsedMilliseconds}. Looked at {lastmove} {allValidMoves.Count} moves, which resulted in {subMoves} submoves"); return allValidMoves.Count+subMoves; }
public override void UndoMove(NormalMove m) { var castling = m as CastlingMove; if (castling != null) { UndoCastle(castling); } else base.UndoMove(m); }
// Supposed to check for checks and other stuff. private NormalMove IsLegalMove(NormalMove normalMove) { // uh-oh var correctMove = normalMove.Piece.IsLegalMove(normalMove,_currentPly); if (normalMove.Piece.Color==ToMove && correctMove!=null) return correctMove; return null; }