示例#1
0
        /// <summary>
        /// Play the given move if it's playable.
        /// Change the turn if the move is valid
        /// </summary>
        /// <param name="column">The given column on the board</param>
        /// <param name="line">The given line on the board</param>
        /// <returns>True if the move is valide, false otherwise</returns>
        public bool PlayMove(int column, int line)
        {
            if (!PlayAgainsIA ||
                (PlayAgainsIA && !WhiteTurn))
            {
                bool validMove = false;

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

                if (validMove)
                {
                    WhiteTurn = !WhiteTurn;
                }

                return(validMove);
            }

            return(false);
        }
示例#2
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);
        }