コード例 #1
0
ファイル: Program.cs プロジェクト: karol7531/SI
        private void RunProgram()
        {
            AiEngine aiEngine1 = new AiEngine(depth);
            AiEngine aiEngine2 = new AiEngine(depth);

            ResetParams();
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Random random = new Random();

            if (gamemode == Gamemode.PlayerVsAi)
            {
                PlayerVsAi(aiEngine1);
            }
            else if (gamemode == Gamemode.AiVsAi)
            {
                for (int i = 1; i <= 7; i++)
                {
                    AiVsAi(aiEngine1, aiEngine2, i);
                }
            }
            PrintResults();
            ResetParams();

            stopwatch.Stop();
            Console.WriteLine($"Game time: {stopwatch.ElapsedMilliseconds}");
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: karol7531/SI
        public State AiMove(AiEngine aiEngine, State state, bool player, MethodType methodType, HeuristicType heuristicType)
        {
            int nodes;
            int aiMove = aiEngine.GetMove(state, player, methodType, heuristicType, out nodes);

            if (player)
            {
                ai2Nodes += nodes;
            }
            else
            {
                ai1Nodes += nodes;
            }
            return(state.NextState(player, aiMove));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: karol7531/SI
        private bool?AiVsAi(AiEngine aiEngine1, AiEngine aiEngine2, int start)
        {
            State state = new State(rows, cols);

            Console.WriteLine("\nAI_1 move:");
            state = state.NextState(false, start - 1);
            Console.WriteLine(state);
            while (state.CanPlace())
            {
                Console.WriteLine("\nAI_2 move:");
                ai2Time += RunWithStopwatch(() =>
                {
                    state = AiMove(aiEngine2, state, true, methodType2, heuristicType2);
                });
                ai2Moves++;
                //Console.WriteLine(state);
                if (state.Points(true, heuristicType2) >= State.pointsWin)
                {
                    Console.WriteLine(state);
                    Console.WriteLine("AI_2 won");
                    ai2Wins++;
                    return(true);
                }

                Console.WriteLine("\nAI_1 move:");
                ai1Time += RunWithStopwatch(() =>
                {
                    state = AiMove(aiEngine1, state, false, methodType1, heuristicType1);
                });
                ai1Moves++;
                //Console.WriteLine(state);
                if (state.Points(false, heuristicType1) >= State.pointsWin)
                {
                    Console.WriteLine(state);
                    Console.WriteLine("AI_1 won");
                    ai1Wins++;
                    return(false);
                }
            }
            return(null);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: karol7531/SI
        private void PlayerVsAi(AiEngine aiEngine)
        {
            Stack <State> stack = new Stack <State>();
            State         state = new State(rows, cols);

            while (state.CanPlace())
            {
                stack.Push(state.Clone());
                Console.WriteLine("\nYour move:");
                string line = Console.ReadLine();
                if (line == "u")
                {
                    stack.Pop(); stack.Pop();
                    state = stack.Pop();
                    Console.WriteLine(state);
                    continue;
                }
                int playerMove = int.Parse(line);
                state = state.NextState(false, playerMove - 1);
                Console.WriteLine(state);
                if (state.Points(false, heuristicType1) >= State.pointsWin)
                {
                    Console.WriteLine("Congratulations, you won");
                    return;
                }

                stack.Push(state.Clone());
                Console.WriteLine("\nAI move:");
                state = AiMove(aiEngine, state, true, methodType1, heuristicType1);
                Console.WriteLine(state);
                if (state.Points(true, heuristicType1) >= State.pointsWin)
                {
                    Console.WriteLine("AI won");
                    return;
                }
            }
        }