コード例 #1
0
ファイル: Player.cs プロジェクト: jamescelliers/TicTacToe
        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);
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: jamescelliers/TicTacToe
        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));
            }
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: jamescelliers/TicTacToe
        private int PlayerMove(TicTacToeMain game)
        {
            int playerInput = game._inputDelegate();

            while (game.IsGameArrayElementTaken(playerInput))
            {
                playerInput = game._inputDelegate();
            }
            return(playerInput);
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: jamescelliers/TicTacToe
        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);
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: jamescelliers/TicTacToe
        //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);
        }
コード例 #6
0
ファイル: Player.cs プロジェクト: jamescelliers/TicTacToe
 private int CPUMoveNormal(TicTacToeMain game)
 {
     return(CPUMoveEasy(game));
 }