Ejemplo n.º 1
0
 //Подготовка к след. ходу
 internal void PrepareNextMove(PieceMove pieceMove)
 {
     moveNumber++;
     inGameColor = inGameColor.FlipColor();
     ParseGameToFEN();
     moves.UpdateMoves(pieceMove);
 }
Ejemplo n.º 2
0
        internal override void MakeMove(PieceMove move, Desk desk)
        {
            List <string> moves = playersMoves.GetPlayerMoves(playerColor);

            lastMove = new PieceMove(playerColor, moves[random.Next(moves.Count)]);

            desk.UpdatePiecesOnDesk(lastMove, playerColor);
        }
Ejemplo n.º 3
0
        private void UsualMoveUpdate(PieceMove pieceMove, ref List <Vectors> activePlayerMoves, ref List <Vectors> waitingPlayerMoves)
        {
            string from = pieceMove.from;
            string to   = pieceMove.to;

            activePlayerMoves.RemoveAll(item => item.status == "delete");

            UpdateMovesLists(from, to, ref activePlayerMoves, ref waitingPlayerMoves);
        }
Ejemplo n.º 4
0
        private void CastlingMoveUpdate(PieceMove pieceMove, ref List <Vectors> activePlayerMoves, ref List <Vectors> waitingPlayerMoves)
        {
            string fromK, toK, fromR, toR;

            fromK = pieceMove.fromK;
            toK   = pieceMove.toK;
            fromR = pieceMove.fromR;
            toR   = pieceMove.toR;

            UpdateMovesLists(fromK, toK, ref activePlayerMoves, ref waitingPlayerMoves);
            UpdateMovesLists(fromR, toR, ref activePlayerMoves, ref waitingPlayerMoves);
        }
Ejemplo n.º 5
0
        //Ход игрока
        public void PlayerMove(string moveName)
        {
            PieceMove     move        = new PieceMove(player1.playerColor, moveName);
            List <string> playerMoves = moves.GetPlayerMoves(player1.playerColor);

            if (playerMoves.Count != 0 && player1.playerColor == game.inGameColor)
            {
                if (playerMoves.Exists(item => item == moveName))
                {
                    player1.MakeMove(move, desk);
                    game.PrepareNextMove(move);
                }
            }
        }
Ejemplo n.º 6
0
        //рокировка (всегда происходит на конкретных клетках, поэтому там присутствуют magic numbers)
        private void MakeCastling(King k, PieceMove pMove)
        {
            pieces[pMove.toKX, pMove.toKY] = pieces[pMove.fromKX, pMove.fromKY];
            pieces[pMove.toKX, pMove.toKY].movesVector.status        = "recalculate";
            pieces[pMove.toKX, pMove.toKY].movesVector.startPosition = pMove.toK;
            pieces[pMove.fromKX, pMove.fromKY] = Piece.nullPiece;

            pieces[pMove.toRX, pMove.toRY] = pieces[pMove.fromRX, pMove.fromRY];
            pieces[pMove.toRX, pMove.toRY].movesVector.status        = "recalculate";
            pieces[pMove.toRX, pMove.toRY].movesVector.startPosition = pMove.toR;
            pieces[pMove.fromRX, pMove.fromRY] = Piece.nullPiece;

            k.shortCastling = false; k.longCastling = false;
        }
Ejemplo n.º 7
0
        public bool IsMateAfterMove(string move, Vectors vector)
        {
            bool      result;
            PieceMove pieceMove          = new PieceMove(inGameColor, move);
            ForsythEdwardsNotation copyN = (ForsythEdwardsNotation)desk.notation.Clone();
            Desk  copyDesk  = new Desk(copyN);
            Moves copyMoves = new Moves(copyDesk);

            copyDesk.UpdatePiecesOnDesk(pieceMove, inGameColor);
            ChessPlayer op = new Bot(inGameColor.FlipColor(), copyMoves, copyDesk);

            result = copyDesk.IsKingInDanger(copyMoves.GetPlayerMoves(op.playerColor), inGameColor);

            if (result && vector.status != "recalculate")
            {
                vector.status = "recalculate";
                RecalculatedPiecesPosition.Add(pieceMove.from);
            }
            return(result);
        }
Ejemplo n.º 8
0
        internal void UpdateMoves(PieceMove pieceMove = null)
        {
            RecalculatedPiecesPosition.Clear();

            inGameColor = desk.notation.InGameColor;

            List <Vectors> activePlayerMoves  = (inGameColor == Color.white) ? whiteMoves : blackMoves;;
            List <Vectors> waitingPlayerMoves = (inGameColor == Color.white) ? blackMoves : whiteMoves;;

            Vectors wKingVector = whiteMoves.Find(item => item.vectorPieceKey == whiteKing);
            Vectors bKingVector = blackMoves.Find(item => item.vectorPieceKey == blackKing);

            wKingVector.avaibleSquares.Remove("0-0-0");
            wKingVector.avaibleSquares.Remove(" 0-0 ");
            bKingVector.avaibleSquares.Remove("0-0-0");
            bKingVector.avaibleSquares.Remove(" 0-0 ");


            if (pieceMove.castling != "none")
            {
                CastlingMoveUpdate(pieceMove, ref activePlayerMoves, ref waitingPlayerMoves);
            }
            else
            {
                UsualMoveUpdate(pieceMove, ref activePlayerMoves, ref waitingPlayerMoves);
            }


            for (int i = 0; i < activePlayerMoves.Count; i++)
            {
                Vectors vector = activePlayerMoves[i];
                vector.avaibleSquares.RemoveAll(item => IsMateAfterMove((char)vector.vectorPieceKey + vector.startPosition + item, vector));
            }
            CheckCastling(inGameColor);
            CheckCastling(inGameColor.FlipColor());

            movesStory.Add(pieceMove.name);
        }
Ejemplo n.º 9
0
 //Сделать ход
 internal abstract void MakeMove(PieceMove move, Desk desk);
Ejemplo n.º 10
0
 internal override void MakeMove(PieceMove move, Desk desk)
 {
     desk.UpdatePiecesOnDesk(move, playerColor);
 }
Ejemplo n.º 11
0
        //Обновить инф. о положении фигур на доске (массивы фигур,клеток и взятых фигур)
        internal void UpdatePiecesOnDesk(PieceMove pieceMove, Color inGameColor)
        {
            curKilledPieceSquare = "none";
            Square kingSq = FindKing(inGameColor);
            King   k      = (King)kingSq.ownedPiece;

            if (pieceMove.name != " 0-0 " && pieceMove.name != "0-0-0")
            {
                int fromX = pieceMove.fromX; int fromY = pieceMove.fromY;
                int toX = pieceMove.toX; int toY = pieceMove.toY;

                //перемещение фигуры
                if (pieces[toX, toY] != Piece.nullPiece)
                {
                    pieces[toX, toY].movesVector.status = "delete";
                    curKilledPieceSquare = pieceMove.to;
                    deadPieces.Add((char)pieces[toX, toY].pieceKey);
                }
                pieces[toX, toY] = pieces[fromX, fromY];
                pieces[toX, toY].movesVector.status        = "recalculate";
                pieces[toX, toY].movesVector.startPosition = pieceMove.to;
                pieces[fromX, fromY] = Piece.nullPiece;

                //взятие на проходе
                if ((pieceMove.pieceKey == blackPawn || pieceMove.pieceKey == whitePawn) && notation.EnPassant == deskSquares[toX, toY].Name)
                {
                    pieces[toX, fromY].movesVector.status = "delete";
                    curKilledPieceSquare = deskSquares[toX, fromY].Name;
                    deadPieces.Add((char)pieces[toX, fromY].pieceKey);
                    pieces[toX, fromY] = Piece.nullPiece;
                }


                //определяем был ли совершен ход пешкой на две клетки
                if (Math.Abs(toY - fromY) == 2 && (pieceMove.pieceKey == blackPawn || pieceMove.pieceKey == whitePawn))
                {
                    notation.EnPassant = deskSquares[(toX + fromX) / 2, (toY + fromY) / 2].Name;
                }
                else
                {
                    notation.EnPassant = "-";
                }

                //превращение пешки (Pe7e8N,Pa7b8Q и т.д.). Превращение фиксируется на 6-ом знаке(если оно есть)
                if (pieceMove.promotion)
                {
                    Piece piece = ParseToPiece(pieceMove.promotionCharKey);
                    pieces[toX, toY] = piece;
                }

                //право рокировки навсегда теряется при ходе короля
                if ((k.shortCastling || k.longCastling) && pieceMove.pieceKey == k.pieceKey)
                {
                    k.shortCastling = false; k.longCastling = false;
                }

                //право рокировки с ладьей навсегда теряется при ходе этой ладьи или ее взятии
                if (k.shortCastling && k.pieceKey == whiteKing && pieces[7, 0].pieceKey != whiteRook)
                {
                    k.shortCastling = false;
                }
                if (k.longCastling && k.pieceKey == whiteKing && pieces[0, 0].pieceKey != whiteRook)
                {
                    k.longCastling = false;
                }
                if (k.shortCastling && k.pieceKey == blackKing && pieces[7, 7].pieceKey != blackRook)
                {
                    k.shortCastling = false;
                }
                if (k.longCastling && k.pieceKey == blackKing && pieces[0, 7].pieceKey != blackRook)
                {
                    k.longCastling = false;
                }
            }
            else
            {
                MakeCastling(k, pieceMove);
            }

            UpdateDeskSquares();
        }