public static bool CheckIfGameOver(bool continuePlaying, PlayerPieces AIWhiteComp, PlayerPieces AIBlackComp)
        {
            bool whiteKingAlive = true;
            bool blackKingAlive = true;

            whiteKingAlive = CheckWhiteKing(AIWhiteComp, whiteKingAlive);
            blackKingAlive = CheckBlackKing(AIBlackComp, blackKingAlive);

            if (whiteKingAlive && blackKingAlive)
            {
                continuePlaying = true;
            }
            else
            {
                continuePlaying = false;
            }

            if ((AIWhiteComp.PieceList.Count == 1) && (AIBlackComp.PieceList.Count == 1))
            {
                Logger.AddMessageToLog("Only Kings remaining, its a draw!");
                continuePlaying = false;
            }

            return(continuePlaying);
        }
Esempio n. 2
0
        //Sets up the move of the current player.
        public List <IChessPiece> MakeMove(PlayerPieces playerToMove, List <IChessPiece> enemyList)
        {
            this.AIToMove            = playerToMove;
            this.EnemyPiecePositions = enemyList;

            List <IChessPiece> AfterMoveList = AIMakeMove(AIToMove);

            return(AfterMoveList);
        }
Esempio n. 3
0
        /* ***** Initiate new game ******* */

        public void CreateAIs()
        {
            bool playerWhite = true;
            bool playerBlack = false;
            bool myTurn      = false;

            AIWhiteComp = new PlayerPieces(playerWhite, myTurn);
            AIBlackComp = new PlayerPieces(playerBlack, myTurn);
        }
 private static bool CheckWhiteKing(PlayerPieces AIWhiteComp, bool whiteKingAlive)
 {
     whiteKingAlive = false;
     foreach (var piece in AIWhiteComp.PieceList)
     {
         if (piece.FullName == "King")
         {
             whiteKingAlive = true;
         }
     }
     return(whiteKingAlive);
 }
 private static bool CheckBlackKing(PlayerPieces AIBlackComp, bool blackKingAlive)
 {
     blackKingAlive = false;
     foreach (var piece in AIBlackComp.PieceList)
     {
         if (piece.FullName == "King")
         {
             blackKingAlive = true;
         }
     }
     return(blackKingAlive);
 }
Esempio n. 6
0
        //Logic deciding which move to make for current player.
        public List <IChessPiece> AIMakeMove(PlayerPieces AIToMove)
        {
            List <List <MovementOptions> > AllMovesMyPiecesCanMake = AnalyzeMyPieces(AIToMove.PieceList, EnemyPiecePositions);

            List <MovementOptions> FilteredMovesToKeepKingSafe = RemoveOptionsThatThreatenKing(AllMovesMyPiecesCanMake);

            Logger.AmountOfLegalAnalyzedMoves(AllMovesMyPiecesCanMake.Count);

            if (FilteredMovesToKeepKingSafe.Count == 0)
            {
                Logger.AddMessageToLog(AIToMove.TeamName + " Has lost the game.");
                AIToMove.PieceList.Clear();
                return(AIToMove.PieceList);
            }

            List <MovementOptions> PiecesICanKill = FindPiecesICanKill(FilteredMovesToKeepKingSafe);

            MovementOptions optimalMovementOption;

            if (PiecesICanKill.Count != 0)
            {
                optimalMovementOption = FindHighestPieceValue(PiecesICanKill);
            }
            else
            {
                List <MovementOptions> MovesWherePieceCanStrikeNextTurn = FindSomeoneToKillNextTurn(FilteredMovesToKeepKingSafe);

                if (MovesWherePieceCanStrikeNextTurn.Count != 0)
                {
                    optimalMovementOption = FindHighestPieceValue(MovesWherePieceCanStrikeNextTurn);
                }
                else
                {
                    int MaxIndex             = FilteredMovesToKeepKingSafe.Count;
                    int randomMovementOption = GetRandomNumber(0, MaxIndex);

                    optimalMovementOption = FilteredMovesToKeepKingSafe[randomMovementOption];
                }
            }
            Logger.LogDecidedMove(optimalMovementOption);

            MovePiece(optimalMovementOption, AIToMove.PieceList, EnemyPiecePositions);

            CheckIfPawnIsAtEndOfBoard(AIToMove.PieceList);

            return(AIToMove.PieceList);
        }
Esempio n. 7
0
 //Constructor generating white and black pieces, also instantiates list of all possible moves, all allowed moves and all pieces that can kill an opponent.
 public AIMoveData(PlayerPieces MyPieces, PlayerPieces EnemyPieces)
 {
     this.AIToMove            = MyPieces;
     this.AINotToMove         = EnemyPieces;
     this.EnemyPiecePositions = EnemyPieces.PieceList;
 }
Esempio n. 8
0
 public void CreateMoveLogic(PlayerPieces AIWhiteComp, PlayerPieces AIBlackComp)
 {
     moveData = new AIMoveData(AIWhiteComp, AIBlackComp);
 }