Example #1
0
        /// <summary>
        /// Play the next move for the IA.
        /// </summary>
        /// <returns>True if the move is valide, false otherwise</returns>
        public bool PlayMoveIA()
        {
            if (PlayAgainsIA && WhiteTurn)
            {
                bool validMove = false;
                int  column, line;

                // TODO needs to be cleaned and improved, meaby moved ? IA's turn
                Tuple <int, int> nextMove = BoardGame.GetNextMove(BoardGame.CurrentBoard, 5, WhiteTurn);

                // IA pass turn if no next possible move
                if (nextMove.Equals(new Tuple <int, int>(-1, -1)))
                {
                    Console.WriteLine("No next move for the IA");
                    Console.Read();
                    WhiteTurn = !WhiteTurn;
                    return(false);
                }

                column = nextMove.Item1;
                line   = nextMove.Item2;

                if (BoardGame.IsPlayable(column, line, WhiteTurn))
                {
                    validMove = BoardGame.PlayMove(column, line, WhiteTurn);
                }

                if (validMove)
                {
                    WhiteTurn   = !WhiteTurn;
                    TurnSkipped = false;
                }

                return(validMove);
            }

            return(false);
        }