Example #1
0
        private int CPUMove(TicTacToeMain game)
        {
            //int movePosition = 0;

            int cpuMove = 1;

            switch (Difficulty)
            {
            case CPUDifficulty.Easy:
                CPUMoveEasy(game);
                break;

            case CPUDifficulty.Normal:
                cpuMove = CPUMoveNormal(game);
                break;

            case CPUDifficulty.Impossible:
                cpuMove = CPUMoveImpossible(game);
                break;

            default:
                CPUMoveEasy(game);
                break;
            }
            return(cpuMove);
        }
Example #2
0
        private int CPUMoveImpossible(TicTacToeMain game)
        {
            List <int> enemyPositions = game.GetEnemyPositions();

            //int cpuMove = 0;
            for (int i = 0; i < enemyPositions.Count; i++)
            {
                Console.WriteLine($"enemy = {OpponentChar} at position {enemyPositions[i]}");
                enemyPositions[i]++;
            }
            switch (game.turnCount)
            {
            case 0:
                return(1);

            case 1:

                if (enemyPositions.Contains(5))
                {
                    return(1);
                }
                else
                {
                    return(5);
                }

            case 2:
                //if (enemyPositions.Intersect(GetEdgeCoorinatesAsList()).Any())
                //{
                //    return 5;
                //}
                //else if (enemyPositions.Contains(5))
                //{
                //    return 9;
                //}
                //else if (enemyPositions.Contains(2) || enemyPositions.Contains(4))
                //{
                //    return 9;
                //}
                //else
                //{
                //    return 7;
                //}
                if (enemyPositions.Contains(5))
                {
                    return(9);
                }
                else
                {
                    return(5);
                }
            //case 3:

            //    break;
            default:
                return(CPUMoveEasy(game));
            }
        }
Example #3
0
        private int PlayerMove(TicTacToeMain game)
        {
            int playerInput = game._inputDelegate();

            while (game.IsGameArrayElementTaken(playerInput))
            {
                playerInput = game._inputDelegate();
            }
            return(playerInput);
        }
Example #4
0
        private int CPUMoveEasy(TicTacToeMain game)
        {
            Random rnd     = new Random();
            int    cpuMove = rnd.Next(1, 10);

            while (game.IsGameArrayElementTaken(cpuMove))
            {
                cpuMove = rnd.Next(1, 10);
            }
            return(cpuMove);
        }
Example #5
0
        //wrapper for CPUMove and PlayerMove
        public int Turn(TicTacToeMain game)
        {
            //check if taken
            int output = 0;

            if (IsCPU)
            {
                output = CPUMove(game);
            }
            else
            {
                output = PlayerMove(game);
            }
            return(output);
        }
Example #6
0
 private int CPUMoveNormal(TicTacToeMain game)
 {
     return(CPUMoveEasy(game));
 }