private void ClonePieces(Piece.PlayerColour playerColour, Board b) { foreach (Piece p in EnumeratePieces(playerColour)) { p.CopyToBoard(b); } }
private void setPiece(int row, int col) { Piece.PlayerColour colour = getPlayerColour(row); if (OnBoundary(row) && OnBoundary(col)) { Place <Rook>(colour, row, col); } else if (OnBoundary(row) && onKnightStart(col)) { Place <Knight>(colour, row, col); } else if (OnBoundary(row) && onBishopStart(col)) { Place <Bishop>(colour, row, col); } else if (OnBoundary(row) && onQueenStart(col)) { Place <Queen>(colour, row, col); } else if (OnBoundary(row) && onKingStart(col)) { Place <King>(colour, row, col); } else if (onPawnStart(row)) { Place <Pawn>(colour, row, col); } }
private IEnumerable <BoardWithHistory> EnumSim(BoardWithHistory currentBoard, Piece.PlayerColour currentColour, int currentMoveNum, Predicate <ConditionalStruct> condition) { if (condition(new ConditionalStruct { Board = currentBoard.Board, MoveCount = currentMoveNum })) { yield return(currentBoard); } else { Piece.PlayerColour nextColour = currentColour == Piece.PlayerColour.White ? Piece.PlayerColour.Black : Piece.PlayerColour.White; foreach (Piece p in currentBoard.Board.EnumeratePieces(currentColour)) { foreach (Cell move in p.GetPossibleMoves()) { Board nextBoard = currentBoard.Board.SimulateMove(p.ParentCell, move); BoardWithHistory nextBWH = new BoardWithHistory() { Board = nextBoard, BoardHistory = currentBoard.BoardHistory + "\r\n\r\n" + nextBoard.BoardString, }; foreach (BoardWithHistory returnedBoard in EnumSim(nextBWH, nextColour, currentMoveNum + 1, condition)) { yield return(returnedBoard); } } } } }
private Board SetupBoardForKnightTest(int row, int col, Piece.PlayerColour colour) { Board b = TestBoard.createBoard(); b.Place <Knight>(colour, row, col); return(b); }
public SimulationTree Simulate(Piece.PlayerColour startColour, Predicate <SimulationTree.SimNode> stopCase) { SimulationTree simTree = new SimulationTree(); simTree.Base = new SimulationTree.SimNode(this, 0); BuildTree(simTree.Base, startColour, stopCase); return(simTree); }
public bool InStalemate(Piece.PlayerColour playerColour) { King k = GetFirstPiece <King>(playerColour); if (k != null) { return(!k.InCheck && Simulate(Piece.PlayerColour.White).Count == 0); } return(false); }
public IEnumerable <T> EnumeratePieceType <T>(Piece.PlayerColour playerColour) where T : Piece { foreach (Piece p in EnumeratePieces(playerColour)) { if (p is T) { yield return((T)p); } } }
public T GetFirstPiece <T>(Piece.PlayerColour playerColour) where T : Piece { IEnumerable <T> pieces = EnumeratePieceType <T>(playerColour); if (pieces.Count() > 0) { return(pieces.First()); } return(null); }
public override List <Cell> GetMoves() { List <Cell> possibleMoves = new List <Cell>(); string boardString = this.gameBoard.BoardString; Piece.PlayerColour colour = this.Colour; foreach (getPossibleMoves getMove in Moves) { possibleMoves.AddRange(getMove()); boardString = this.gameBoard.BoardString; } return(possibleMoves); }
public void Replace <T>(int row, int col) where T : Piece { if (isPawn(row, col) && isTypePawnPromotionCondidate(typeof(T))) { Piece.PlayerColour colour = this[row, col].Piece.Colour; Place <T>(colour, row, col); } else { throw new ApplicationException(String.Format("Cannot replace {0}.", this[row, col].Piece.ToString())); } }
public List <Board> Simulate(Piece.PlayerColour playerColour) { List <Board> simBoards = new List <Board>(); foreach (Piece p in EnumeratePieces(playerColour)) { foreach (Cell move in p.GetPossibleMoves()) { simBoards.Add(SimulateMove(p.ParentCell, move)); } } return(simBoards); }
public IEnumerable <Piece> EnumeratePieces(Piece.PlayerColour playerColour) { for (int row = 0; row < NumOfRows; row++) { for (int col = 0; col < NumOfCols; col++) { if (this[row, col].Piece.Colour == playerColour) { yield return(this[row, col].Piece); } } } }
public IEnumerable <BoardWithHistory> EnumSimTill(Piece.PlayerColour startColour, Predicate <ConditionalStruct> condition) { Board copyOfBoard = this.Clone() as Board; BoardWithHistory copyOfBoardWH = new BoardWithHistory() { Board = copyOfBoard, BoardHistory = copyOfBoard.BoardString, }; foreach (BoardWithHistory simBoard in EnumSim(copyOfBoardWH, startColour, 0, condition)) { yield return(simBoard); } }
public bool isCellVulnerableAfterMove(GameCell fromCell, GameCell toCell, Piece.PlayerColour opposingColour) { Piece pieceToMove = fromCell.Piece; Piece pieceAtToCell = toCell.Piece; MovePieceOnBoard(fromCell, toCell); bool isVulnerable = isCellVulnerable(toCell, opposingColour); fromCell.Piece = pieceToMove; toCell.Piece = pieceAtToCell; return(isVulnerable); }
public bool isCellVulnerable(Cell cell, Piece.PlayerColour opposingColour) { bool isVulnerable = false; foreach (Piece p in EnumeratePieces(opposingColour)) { p.VulnerableCheck = true; if (p.GetMoves().Contains(cell)) { isVulnerable = true; break; } p.VulnerableCheck = false; } return(isVulnerable); }
private void BuildTree(SimulationTree.SimNode currentNode, Piece.PlayerColour toMove, Predicate <SimulationTree.SimNode> stopCase) { if (stopCase(currentNode)) { return; } foreach (Board nextMoveBoard in currentNode.Board.Simulate(toMove)) { SimulationTree.SimNode nextMoveNode = new SimulationTree.SimNode(nextMoveBoard, currentNode.NumOfMoves + 1); currentNode.NextMoves.Add(nextMoveNode); } currentNode.Board = null; foreach (SimulationTree.SimNode node in currentNode.NextMoves) { Piece.PlayerColour nextColour = toMove == Piece.PlayerColour.White ? Piece.PlayerColour.Black : Piece.PlayerColour.White; BuildTree(node, nextColour, stopCase); } }
public void Place <T>(Piece.PlayerColour colour, int row, int col) where T : Piece { this[row, col].Piece = (T)Activator.CreateInstance(typeof(T), colour, this[row, col], this); }
public IEnumerable <BoardWithHistory> EnumSimTillNumMovesAhead(int numMovesAhead, Piece.PlayerColour startColour) { return(EnumSimTill(startColour, A => A.MoveCount == numMovesAhead)); }
public SimulationTree Simulate(Piece.PlayerColour startColour, int numOfMoves) { return(Simulate(startColour, Node => Node.NumOfMoves == numOfMoves)); }