Example #1
0
    private void Cycle()
    {
        CurveSearch <Chess.ChessBoard, Chess.ChessMove, ChessStrategy, ChessTactic> search = board.IsPlayerOneActive() ? searchP1 : searchP2;

        for (int i = 0; i < cycleCount; i++)
        {
            search.Cycle();
        }

        Chess.ChessMove move = search.GetAndSetNext();

        Vector2Int from = move.From, to = move.To;

        Debug.Log((!board.IsPlayerOneActive() ? "White" : "Black") + " from " + from + ", to " + to);
    }
Example #2
0
        /// <summary>
        /// Returns list of All legal ChessMoves for a GamePiece
        /// </summary>
        /// <param name="piece">GamePiece that is being investigated</param>
        public List <ChessMove> PossibleMoves(GamePiece piece)
        {
            if (piece is null)
            {
                return(null); // illegal - Empty space
            }
            Player           activePlayer  = piece.TeamColor == PlayerOne.TeamColor ? PlayerOne : PlayerTwo;
            Cell             fromCell      = Cells.GetCell(piece.Location);
            List <ChessMove> possibleMoves = new List <ChessMove>(); // Returning List of Possible Moves
            GamePiece        king          = activePlayer.MyPieces.Find(gp => gp is King);

            //List<BlindMove> blindMoves = fromCell.Piece.BlindMoves(); // Blind move instructions for Gamepiece
            foreach (BlindMove bMove in fromCell.Piece.BlindMoves())             // Blind move instructions for Gamepiece
            {
                Cell      focusCell = Cells.NextCell(fromCell, bMove.Direction); // The Starting Point
                int       moveCount = 0;
                Condition moveType  = Condition.Neutral;

                // Increment through Instruction
                while (!(focusCell is null) && bMove.Limit != moveCount && moveType == Condition.Neutral)
                {
                    moveType = MovePossibility(fromCell.Piece, fromCell, focusCell, bMove.Condition);

                    // ADD to List of Possible ChessMoves
                    if (moveType == Condition.Neutral || moveType == Condition.Attack || moveType == Condition.enPassant || moveType == Condition.Castling)
                    {
                        ChessMove move;
                        if (moveType == Condition.enPassant) // *Special Move - Pawn captures Pawn via Enpassant
                        {
                            GamePiece captured = Cells.Find(c => !(c.enPassantPawn is null)).enPassantPawn;
                            move = new ChessMove(fromCell, focusCell, fromCell.Piece, captured, moveType, Cells.GetCell(captured.Location));
                        }
                        else if (moveType == Condition.Castling) // *Special Move - Castling, insert Rook into ChessMove
                        {
                            Rook rook       = (Rook)Cells.GetCell((Point)bMove.OtherInfo).Piece;
                            int  xDirection = bMove.Direction.X / 2;
                            Cell rookFrom   = Cells.GetCell(rook.Location);
                            Cell rookTo     = Cells.GetCell(new Point(fromCell.ID.X + xDirection, fromCell.ID.Y));

                            ChessMove rookMove = new ChessMove(rookFrom, rookTo, rook, null, Condition.Castling);

                            move = new ChessMove(fromCell, focusCell, fromCell.Piece, null, moveType, rookMove);
                        }
                        else // Regular Move
                        {
                            move = new ChessMove(fromCell, focusCell, fromCell.Piece, focusCell.Piece, moveType);
                        }

                        //Look in the future
                        move = MovePiece(move, true);
                        bool isKingSafe = IsSafe(king.Location, activePlayer);
                        move = UndoMovePiece(move, true);

                        if (isKingSafe)
                        {
                            possibleMoves.Add(move);
                        }
                    }

                    focusCell = Cells.NextCell(focusCell, bMove.Direction);
                    moveCount++;
                }
            }

            return(possibleMoves);
        }