Пример #1
0
        public void IdentifyDiagonalStraightFromRightTop()
        {
            var moveList   = new MoveList();
            var winChecker = new WinChecker();

            moveList.AddMove(new Move(2, 2));
            moveList.AddMove(new Move(2, 3));
            moveList.AddMove(new Move(1, 3));
            moveList.AddMove(new Move(3, 1));

            bool diagonal3InARow = winChecker.CheckForDiagonalWin(moveList.Moves);

            Assert.True(diagonal3InARow);
        }
Пример #2
0
        public void IdentifyADiagonalWinFromLeftTop()
        {
            var moveList   = new MoveList();
            var winChecker = new WinChecker();

            moveList.AddMove(new Move(2, 2));
            moveList.AddMove(new Move(2, 3));
            moveList.AddMove(new Move(1, 1));
            moveList.AddMove(new Move(3, 3));

            var didUserWin = winChecker.CheckForWin(moveList);

            Assert.True(didUserWin);
        }
Пример #3
0
        public void IdentifyNotADiagonalWin()
        {
            var moveList   = new MoveList();
            var winChecker = new WinChecker();

            moveList.AddMove(new Move(2, 1));
            moveList.AddMove(new Move(2, 3));
            moveList.AddMove(new Move(1, 1));
            moveList.AddMove(new Move(3, 3));

            var diagonal3InARow = winChecker.CheckForDiagonalWin(moveList.Moves);

            Assert.False(diagonal3InARow);
        }
Пример #4
0
        public void IndentifyAUserDidntWin()
        {
            var moveList   = new MoveList();
            var winChecker = new WinChecker();

            moveList.AddMove(new Move(2, 2));
            moveList.AddMove(new Move(2, 3));
            moveList.AddMove(new Move(1, 3));
            moveList.AddMove(new Move(3, 2));

            var didUserWin = winChecker.CheckForWin(moveList);

            Assert.False(didUserWin);
        }
Пример #5
0
        public void IndenifyThisRandomWin()
        {
            var moveList   = new MoveList();
            var winChecker = new WinChecker();

            moveList.AddMove(new Move(2, 4));
            moveList.AddMove(new Move(4, 2));
            moveList.AddMove(new Move(1, 3));
            moveList.AddMove(new Move(3, 3));

            bool diagonal3InARow = winChecker.CheckForDiagonalWin(moveList.Moves);

            Assert.True(diagonal3InARow);
        }
Пример #6
0
        public void IndentifyAHorizontalWin()
        {
            var moveList   = new MoveList();
            var winChecker = new WinChecker();

            moveList.AddMove(new Move(2, 2));
            moveList.AddMove(new Move(2, 3));
            moveList.AddMove(new Move(1, 3));
            moveList.AddMove(new Move(3, 3));

            var didUserWin = winChecker.CheckForWin(moveList);

            Assert.True(didUserWin);
        }
Пример #7
0
        public void CheckIfListContains3StraightInARow()
        {
            var moveList   = new MoveList();
            var winChecker = new WinChecker();

            moveList.AddMove(new Move(1, 2));
            moveList.AddMove(new Move(2, 2));
            moveList.AddMove(new Move(1, 1));
            moveList.AddMove(new Move(1, 3));

            var listOfX = winChecker.AddXCoordinatesIntoSortedList(moveList.Moves);
            var result  = winChecker.ContainsStraightLine(listOfX);

            Assert.True(result);
        }
Пример #8
0
        public void RetainMoves()
        {
            var moveList = new MoveList();

            moveList.AddMove(new Move(1, 1));
            moveList.AddMove(new Move(2, 2));
            moveList.AddMove(new Move(2, 3));

            var expectedMovesList = new List <Move>
            {
                new Move(1, 1), new Move(2, 2), new Move(2, 3)
            };

            ContainsSameItems(expectedMovesList, moveList);
        }
Пример #9
0
        public override MoveEventResponse MoveBeingGenerated(MoveList moves, int from, int to, MoveType type)
        {
            int nSquaresOnFirstBoard = Board.NumSquares / 2;

            if (type == MoveType.StandardMove)
            {
                if (to >= nSquaresOnFirstBoard)
                {
                    if (Board[to - nSquaresOnFirstBoard] == null)
                    {
                        moves.AddMove(from, to - nSquaresOnFirstBoard, true);
                    }
                }
                else
                {
                    if (Board[to + nSquaresOnFirstBoard] == null)
                    {
                        moves.AddMove(from, to + nSquaresOnFirstBoard, true);
                    }
                }
                return(MoveEventResponse.Handled);
            }
            else if (type == MoveType.StandardCapture)
            {
                if (to >= nSquaresOnFirstBoard)
                {
                    moves.BeginMoveAdd(MoveType.StandardCapture, from, to - nSquaresOnFirstBoard);
                    Piece pieceBeingMoved    = moves.AddPickup(from);
                    Piece pieceBeingCaptured = moves.AddPickup(to);
                    moves.AddDrop(pieceBeingMoved, to - nSquaresOnFirstBoard);
                    moves.EndMoveAdd(3000 +
                                     pieceBeingCaptured.PieceType.MidgameValue -
                                     (pieceBeingMoved.PieceType.MidgameValue / 16));
                }
                else
                {
                    moves.BeginMoveAdd(MoveType.StandardCapture, from, to + nSquaresOnFirstBoard);
                    Piece pieceBeingMoved    = moves.AddPickup(from);
                    Piece pieceBeingCaptured = moves.AddPickup(to);
                    moves.AddDrop(pieceBeingMoved, to + nSquaresOnFirstBoard);
                    moves.EndMoveAdd(3000 +
                                     pieceBeingCaptured.PieceType.MidgameValue -
                                     (pieceBeingMoved.PieceType.MidgameValue / 16));
                }
                return(MoveEventResponse.Handled);
            }
            return(MoveEventResponse.NotHandled);
        }
Пример #10
0
        public void AddAMoveToMoveList()
        {
            var move     = new Move(2, 2);
            var moveList = new MoveList();

            moveList.AddMove(move);
        }
Пример #11
0
        public void PutXCoordinatesIntoASortedIntegerList()
        {
            var moveList   = new MoveList();
            var winChecker = new WinChecker();

            moveList.AddMove(new Move(1, 2));
            moveList.AddMove(new Move(2, 2));
            moveList.AddMove(new Move(1, 1));
            moveList.AddMove(new Move(1, 3));

            var result       = winChecker.AddXCoordinatesIntoSortedList(moveList.Moves);
            var expectedList = new List <int> {
                1, 1, 1, 2
            };

            Assert.Equal(expectedList, result);
        }
Пример #12
0
        private void AddSingleStepMove(int directionY, ref MoveList moveList)
        {
            var oneStep = _position.PhysicalY + directionY;

            if (oneStep.IsOnBoard() && _board.PositionIsFree(_position.PhysicalX, oneStep))
            {
                moveList.AddMove(_piece, _position, _position.PhysicalX, oneStep);
            }
        }
Пример #13
0
        public override MoveEventResponse MoveBeingGenerated(MoveList moves, int from, int to, MoveType type)
        {
            Piece movingPiece = Board[from];

            if (movingPiece.TypeNumber == promotingTypeNumber)
            {
                Location        loc    = Board.SquareToLocation(Board.PlayerSquare(movingPiece.Player, to));
                PromotionOption option = condition(loc);
                if (option != PromotionOption.CannotPromote)
                {
                    //	enemy piece being captured (if any)
                    Piece capturedEnemyPiece = Board[to];

                    //	if promotion is optional, add move without promotion
                    if (option == PromotionOption.CanPromote)
                    {
                        if (capturedEnemyPiece == null)
                        {
                            moves.AddMove(from, to, true);
                        }
                        else
                        {
                            moves.AddCapture(from, to, true);
                        }
                    }

                    List <int>   pieceTypesFound = new List <int>();
                    List <Piece> capturedPieces  = Game.GetCapturedPieceList(movingPiece.Player);
                    foreach (Piece capturedFriendlyPiece in capturedPieces)
                    {
                        if (capturedFriendlyPiece.TypeNumber != movingPiece.TypeNumber &&
                            !pieceTypesFound.Contains(capturedFriendlyPiece.TypeNumber))
                        {
                            if (capturedEnemyPiece == null)
                            {
                                moves.BeginMoveAdd(MoveType.MoveReplace, from, to, capturedFriendlyPiece.TypeNumber);
                                moves.AddPickup(from);
                                moves.AddDrop(capturedFriendlyPiece, to);
                                moves.EndMoveAdd(5000 + capturedFriendlyPiece.PieceType.MidgameValue);
                            }
                            else
                            {
                                moves.BeginMoveAdd(MoveType.CaptureReplace, from, to, capturedFriendlyPiece.TypeNumber);
                                moves.AddPickup(from);
                                moves.AddPickup(to);
                                moves.AddDrop(capturedFriendlyPiece, to);
                                moves.EndMoveAdd(5000 + capturedFriendlyPiece.PieceType.MidgameValue + capturedEnemyPiece.PieceType.MidgameValue);
                            }
                            pieceTypesFound.Add(capturedFriendlyPiece.TypeNumber);
                        }
                    }
                    return(MoveEventResponse.Handled);
                }
            }
            return(MoveEventResponse.NotHandled);
        }
Пример #14
0
        private void AddCapture(int directionX, int directionY, ref MoveList moveList)
        {
            var oneStep = _position.PhysicalY + directionY;

            var side = _position.PhysicalX + directionX;

            if (side.IsOnBoard() && !_board.PositionIsFree(side, oneStep))
            {
                moveList.AddMove(_piece, _position, side, oneStep);
            }
        }
Пример #15
0
        public static bool CustomMoveGenerationHandler(PieceType pieceType, Piece piece, MoveList moveList, bool capturesOnly)
        {
            MoveCapability[] moves;
            int nMoves = pieceType.GetMoveCapabilities(out moves);

            for (int nMove = 0; nMove < nMoves; nMove++)
            {
                MoveCapability move       = moves[nMove];
                int            step       = 1;
                int            nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, piece.Square);
                while (nextSquare >= 0 && step <= move.MaxSteps)
                {
                    Piece pieceOnSquare = piece.Board[nextSquare];
                    if (pieceOnSquare != null)
                    {
                        if (step >= move.MinSteps && move.CanCapture && pieceOnSquare.Player != piece.Player)
                        {
                            moveList.AddCapture(piece.Square, nextSquare);
                        }
                        else if (step >= move.MinSteps && pieceOnSquare.Player == piece.Player && piece.PieceType != pieceOnSquare.PieceType)
                        {
                            //	self-capture move allowing relocation of friendly piece
                            int currentSquare = piece.Square;
                            while (currentSquare != nextSquare)
                            {
                                moveList.BeginMoveAdd(MoveType.MoveRelay, piece.Square, nextSquare, currentSquare);
                                moveList.AddPickup(piece.Square);
                                moveList.AddPickup(nextSquare);
                                moveList.AddDrop(piece, nextSquare);
                                moveList.AddDrop(pieceOnSquare, currentSquare);
                                moveList.EndMoveAdd(piece.PieceType.GetMidgamePST(nextSquare) - piece.PieceType.GetMidgamePST(piece.Square) +
                                                    pieceOnSquare.PieceType.GetMidgamePST(currentSquare) - pieceOnSquare.PieceType.GetMidgamePST(nextSquare));
                                currentSquare = piece.Board.NextSquare(piece.Player, move.NDirection, currentSquare);
                            }
                        }
                        nextSquare = -1;
                    }
                    else
                    {
                        if (step >= move.MinSteps && !move.MustCapture && !capturesOnly)
                        {
                            moveList.AddMove(piece.Square, nextSquare);
                        }
                        nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, nextSquare);
                        step++;
                    }
                }
            }
            return(false);
        }
Пример #16
0
        private void AddInitialDoubleStepMove(int homeY, int directionY, ref MoveList moveList)
        {
            if (_position.PhysicalY != homeY)
            {
                return;
            }

            var doubleStep = _position.PhysicalY + directionY + directionY;

            if (_board.PositionIsFree(_position.PhysicalX, doubleStep))
            {
                moveList.AddMove(_piece, _position, _position.PhysicalX, doubleStep);
            }
        }
Пример #17
0
        // *** HELPER FUNCTIONS *** //

        #region addMove
        protected void addMove(MoveList list, int fromSquare, int toSquare, bool capturesOnly)
        {
            if (toSquare >= 0 && toSquare < Board.NumSquares)
            {
                Piece pieceOnDestinationSquare = Board[toSquare];
                if (pieceOnDestinationSquare == null)
                {
                    if (!capturesOnly)
                    {
                        list.AddMove(fromSquare, toSquare);
                    }
                }
                else if (pieceOnDestinationSquare.Player != Game.CurrentSide)
                {
                    list.AddCapture(fromSquare, toSquare);
                }
            }
        }
Пример #18
0
        public override MoveEventResponse MoveBeingGenerated(MoveList moves, int from, int to, MoveType type)
        {
            Piece movingPiece = Board[from];

            foreach (PromotionCapability promotion in promotionCapabilities)
            {
                if (movingPiece.TypeNumber == promotion.PromotingTypeNumber)
                {
                    Location        toLocation = Board.SquareToLocation(Board.PlayerSquare(movingPiece.Player, to));
                    PromotionOption option     = promotion.FromAndToConditionDelegate != null
                                                ? promotion.FromAndToConditionDelegate(Board.SquareToLocation(Board.PlayerSquare(movingPiece.Player, from)), toLocation)
                                                : promotion.ConditionDelegate(toLocation);

                    if (option != PromotionOption.CannotPromote)
                    {
                        for (int x = 0; x < Game.MAX_PIECE_TYPES; x++)
                        {
                            typesUsed[x] = false;
                        }

                        //	enemy piece being captured (if any)
                        Piece capturedPiece = Board[to];

                        //	if promotion is optional, add move without promotion
                        if (option == PromotionOption.CanPromote)
                        {
                            if (capturedPiece == null)
                            {
                                moves.AddMove(from, to, true);
                            }
                            else
                            {
                                moves.AddCapture(from, to, true);
                            }
                        }

                        //	handle traditional promotion
                        if (promotion.PromotionTypes != null)
                        {
                            if (capturedPiece == null)
                            {
                                foreach (PieceType promoteTo in promotion.PromotionTypes)
                                {
                                    moves.BeginMoveAdd(MoveType.MoveWithPromotion, from, to);
                                    moves.AddPickup(from);
                                    moves.AddDrop(movingPiece, to, promoteTo);
                                    moves.EndMoveAdd(5000 + promoteTo.MidgameValue);
                                    typesUsed[promoteTo.TypeNumber] = true;
                                }
                            }
                            else
                            {
                                foreach (PieceType promoteTo in promotion.PromotionTypes)
                                {
                                    moves.BeginMoveAdd(MoveType.CaptureWithPromotion, from, to);
                                    moves.AddPickup(from);
                                    moves.AddPickup(to);
                                    moves.AddDrop(movingPiece, to, promoteTo);
                                    moves.EndMoveAdd(5000 + promoteTo.MidgameValue + capturedPiece.PieceType.MidgameValue);
                                    typesUsed[promoteTo.TypeNumber] = true;
                                }
                            }
                        }

                        //	handle promotion by replacement
                        if (promotion.ReplacementPromotionTypes != null)
                        {
                            List <Piece> capturedPieces = Game.GetCapturedPieceList(movingPiece.Player);
                            foreach (Piece capturedFriendlyPiece in capturedPieces)
                            {
                                if (capturedFriendlyPiece.TypeNumber != movingPiece.TypeNumber &&
                                    !typesUsed[capturedFriendlyPiece.TypeNumber] &&
                                    promotion.ReplacementPromotionTypes.Contains(capturedFriendlyPiece.PieceType))
                                {
                                    if (capturedPiece == null)
                                    {
                                        moves.BeginMoveAdd(MoveType.MoveReplace, from, to, capturedFriendlyPiece.TypeNumber);
                                        moves.AddPickup(from);
                                        moves.AddDrop(capturedFriendlyPiece, to);
                                        moves.EndMoveAdd(5000 + capturedFriendlyPiece.PieceType.MidgameValue);
                                    }
                                    else
                                    {
                                        moves.BeginMoveAdd(MoveType.CaptureReplace, from, to, capturedFriendlyPiece.TypeNumber);
                                        moves.AddPickup(from);
                                        moves.AddPickup(to);
                                        moves.AddDrop(capturedFriendlyPiece, to);
                                        moves.EndMoveAdd(5000 + capturedFriendlyPiece.PieceType.MidgameValue + capturedPiece.PieceType.MidgameValue);
                                    }
                                    typesUsed[capturedFriendlyPiece.TypeNumber] = true;
                                }
                            }
                        }
                        return(MoveEventResponse.Handled);
                    }
                }
            }
            return(MoveEventResponse.NotHandled);
        }
Пример #19
0
        public static bool CustomMoveGenerationHandler(PieceType pieceType, Piece piece, MoveList moveList, bool capturesOnly)
        {
            MoveCapability[] moves;
            int nMoves = pieceType.GetMoveCapabilities(out moves);

            for (int nMove = 0; nMove < nMoves; nMove++)
            {
                MoveCapability move       = moves[nMove];
                int            step       = 1;
                int            nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, piece.Square);
                while (nextSquare >= 0 && step <= move.MaxSteps)
                {
                    Piece pieceOnSquare = piece.Board[nextSquare];
                    if (pieceOnSquare != null)
                    {
                        if (step >= move.MinSteps && move.CanCapture && pieceOnSquare.Player != piece.Player)
                        {
                            moveList.AddCapture(piece.Square, nextSquare);
                            for (int x = 0; x < 8; x++)
                            {
                                int targetSquare = piece.Board.NextSquare(x, nextSquare);
                                if (targetSquare >= 0 && piece.Board[targetSquare] != null && piece.Board[targetSquare].Player != piece.Player)
                                {
                                    moveList.BeginMoveAdd(MoveType.ExtraCapture, piece.Square, nextSquare, targetSquare);
                                    moveList.AddPickup(piece.Square);
                                    moveList.AddPickup(nextSquare);
                                    moveList.AddPickup(targetSquare);
                                    moveList.AddDrop(piece, nextSquare);
                                    moveList.EndMoveAdd(4000 + piece.Board[nextSquare].PieceType.MidgameValue + piece.Board[targetSquare].PieceType.MidgameValue);
                                }
                            }
                        }
                        nextSquare = -1;
                    }
                    else
                    {
                        if (step >= move.MinSteps && !move.MustCapture)
                        {
                            if (!capturesOnly)
                            {
                                moveList.AddMove(piece.Square, nextSquare);
                            }
                            for (int x = 0; x < 8; x++)
                            {
                                int targetSquare = piece.Board.NextSquare(x, nextSquare);
                                if (targetSquare >= 0 && piece.Board[targetSquare] != null && piece.Board[targetSquare].Player != piece.Player)
                                {
                                    moveList.BeginMoveAdd(MoveType.ExtraCapture, piece.Square, nextSquare, targetSquare);
                                    moveList.AddPickup(piece.Square);
                                    moveList.AddPickup(targetSquare);
                                    moveList.AddDrop(piece, nextSquare);
                                    moveList.EndMoveAdd(3000 + piece.Board[targetSquare].PieceType.MidgameValue);
                                }
                            }
                        }
                        nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, nextSquare);
                        step++;
                    }
                }
            }

            return(false);
        }
Пример #20
0
        public static bool CustomMoveGenerationHandler(PieceType pieceType, Piece piece, MoveList moveList, bool capturesOnly)
        {
            OdinsRuneChess game = (OdinsRuneChess)piece.Game;

            //	determine what pieces are adjacent
            bool foundValkyrie = false;
            bool foundForestOx = false;
            bool foundRook     = false;
            bool foundBishop   = false;
            bool foundPawn     = false;

            for (int x = 0; x < 8; x++)
            {
                int square = piece.Board.NextSquare(x, piece.Square);
                if (square >= 0 && piece.Board[square] != null && piece.Board[square].Player == piece.Player)
                {
                    PieceType adjacentPieceType = piece.Board[square].PieceType;
                    if (adjacentPieceType == game.Valkyrie)
                    {
                        foundValkyrie = true;
                    }
                    else if (adjacentPieceType == game.ForestOx)
                    {
                        foundForestOx = true;
                    }
                    else if (adjacentPieceType == game.Rook)
                    {
                        foundRook = true;
                    }
                    else if (adjacentPieceType == game.Bishop)
                    {
                        foundBishop = true;
                    }
                    else if (adjacentPieceType == game.Pawn)
                    {
                        foundPawn = true;
                    }
                }
            }

            //	generate moves of appropriate types
            if (foundValkyrie)
            {
                piece.GenerateMoves(game.Valkyrie, moveList, capturesOnly);
            }
            else
            {
                //	don't generate rook or bishop if we have found valkyrie
                //	because all their moves would be redundant
                if (foundRook)
                {
                    piece.GenerateMoves(game.Rook, moveList, capturesOnly);
                }
                if (foundBishop)
                {
                    piece.GenerateMoves(game.Bishop, moveList, capturesOnly);
                }
            }
            if (foundForestOx)
            {
                piece.GenerateMoves(game.ForestOx, moveList, capturesOnly);
            }
            if (foundPawn)
            {
                if (!foundBishop && !foundValkyrie)
                {
                    piece.GenerateMoves(game.Pawn, moveList, capturesOnly);
                }
                else
                {
                    //	This gets tricky; we can't just generate all pawn moves
                    //	because we'd generate duplicative moves.  So we need to
                    //	manually generate just the one unique pawn move (the
                    //	multi-path move.)

                    //	First, check to make sure that this move wasn't
                    //	already generated by a straight Valkyrie move
                    if (!foundValkyrie ||
                        (game.Board.NextSquare(PredefinedDirections.N + piece.Player, piece.Square) >= 0 &&
                         game.Board[game.Board.NextSquare(PredefinedDirections.N + piece.Player, piece.Square)] != null))
                    {
                        //	Is the square two ahead both on the board and a square
                        //	we can move to?
                        int targetSquare = game.Board.NextSquare(PredefinedDirections.N + piece.Player, piece.Square);
                        if (targetSquare >= 0)
                        {
                            targetSquare = game.Board.NextSquare(PredefinedDirections.N + piece.Player, targetSquare);
                        }
                        if (targetSquare >= 0 &&
                            ((game.Board[targetSquare] == null && !capturesOnly) ||
                             (game.Board[targetSquare] != null && game.Board[targetSquare].Player != piece.Player)))
                        {
                            //	This is a square we can move to, but first we
                            //	must establish that there's a clear path
                            if ((game.Board.NextSquare(PredefinedDirections.NE + piece.Player, piece.Square) >= 0 &&
                                 game.Board[game.Board.NextSquare(PredefinedDirections.NE + piece.Player, piece.Square)] == null) ||
                                (game.Board.NextSquare(PredefinedDirections.NW + piece.Player, piece.Square) >= 0 &&
                                 game.Board[game.Board.NextSquare(PredefinedDirections.NW + piece.Player, piece.Square)] == null))
                            {
                                //	Ok, we're clear to generate the move/capture
                                if (game.Board[targetSquare] == null)
                                {
                                    moveList.AddMove(piece.Square, targetSquare);
                                }
                                else
                                {
                                    moveList.AddCapture(piece.Square, targetSquare);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }