Beispiel #1
0
        private static void PlayGame(GameManager gameManager, GameStateStats gameStateStats, List <string> gameArchive, DepthFirstSearch depthFirstSearch, ComputerPlayer[] computerPlayers)
        {
            while (!gameManager.IsGameOver)
            {
                if (!gameManager.HasPlays)
                {
                    gameManager.NextTurn();
                    continue;
                }

                short?computerPlayIndex = null;

                gameStateStats.GenerateStats(gameManager, gameArchive);

                DepthFirstSearch.AnalysisNodeCollection.ClearMemory();
                depthFirstSearch.GetPlayWithBook(gameManager, gameStateStats, computerPlayers[gameManager.PlayerIndex], ref computerPlayIndex);

                //Console.Write(gameManager.Turn);
                //gameManager.Draw();
                //Console.WriteLine("Play " + computerPlayIndex.ToAlgebraicNotation());

                gameManager.PlacePiece(computerPlayIndex);
                gameManager.NextTurn();
            }
        }
Beispiel #2
0
        public void FullySymmetryTest()
        {
            var gameArchive = new List <string> {
                @"\MBJC[]ZUV^DRQbYcIOdkme<XiNn@HPAlj8aF_=GWf5:ogE;243>h`70?619,W",
                @"\MBJC[]ZUV^DRQbYcIOdkmeji<AW_nHgP:aflh2`X9o@031N8;4EG=5F?>76,B",
                @"\MBJC[]ZUV^DRQbYcIOe@HdmNjA<klPX`:ahif=WE;F8on4239g_0156?>7G,0",
                @"\MBJC[]ZUV^DRQbYcIWdkme<Xj@NiHPA8n9:a0l`ohGfFE=Og_215643;>7?,W",
                @"\MBJC[]ZUV^DRQbYceIdm_=AF<NEW;Xkgj43HP5621:Ofo@ln809?>7G`aih,B",
                @"\MBJC[]ZUV^DRQbc=eY;djkl<XOA3I@:25HiNF41E6GW>P`9_fgah?708onm,B",
                @"\MBJC[]ZUV^DRQbcY;OdlekXmAHfNWFEGI<543=6:@P29>7?1`hjon_gia80,B",
            };

            var gameManager = new GameManager();

            var positionStats = new GameStateStats();

            var canDraw        = false;
            var statsAvailable = false;

            positionStats.GenerateStats(gameManager, gameArchive, ref canDraw, ref statsAvailable);

            Assert.IsTrue(positionStats.PlayStats.ContainsKey((short)"e6".ToIndex()));
            Assert.IsTrue(positionStats.PlayStats.ContainsKey((short)"d3".ToIndex()));
            Assert.IsTrue(positionStats.PlayStats.ContainsKey((short)"c4".ToIndex()));
            Assert.IsTrue(positionStats.PlayStats.ContainsKey((short)"f5".ToIndex()));
        }
        public void GetPlayWithBook(GameManager gameManager, GameStateStats gameStateStats, ComputerPlayer computerPlayer, ref short?computerPlayIndex)
        {
            if (computerPlayer.PlayerUiSettings.UseOpeningBook)
            {
                computerPlayIndex = BestBookPlay(gameStateStats.PlayStats, gameManager.PlayerIndex);
                if (computerPlayIndex != null) // Found a play in the opening book
                {
                    return;
                }
            }

            computerPlayIndex = GetPlay(gameManager, computerPlayer);
        }
Beispiel #4
0
    void GeneratePositionStats()
    {
        if (IsReplaying)
        {
            return;
        }

        var position = _gameManager.Plays.ToChars();

        if (!_positionStats.ContainsKey(position))
        {
            _statsAvailable = false;
            var gameStateStats = new GameStateStats();
            _positionStats.Add(position, gameStateStats);
            var thread = new Thread(() => gameStateStats.GenerateStats(_gameManager, GameArchive, ref _canDrawStats, ref _statsAvailable));
            thread.Start();
        }
        else
        {
            _canDrawStats = true;
        }
    }
Beispiel #5
0
        public void Test()
        {
            var gameArchive = new List <string> {
                @"\MBJC[]ZUV^DRQbYcIOdkme<XiNn@HPAlj8aF_=GWf5:ogE;243>h`70?619,W",
                @"\MBJC[]ZUV^DRQbYcIOdkmeji<AW_nHgP:aflh2`X9o@031N8;4EG=5F?>76,B",
                @"\MBJC[]ZUV^DRQbYcIOe@HdmNjA<klPX`:ahif=WE;F8on4239g_0156?>7G,0",
                @"\MBJC[]ZUV^DRQbYcIWdkme<Xj@NiHPA8n9:a0l`ohGfFE=Og_215643;>7?,W",
                @"\MBJC[]ZUV^DRQbYceIdm_=AF<NEW;Xkgj43HP5621:Ofo@ln809?>7G`aih,B",
                @"\MBJC[]ZUV^DRQbc=eY;djkl<XOA3I@:25HiNF41E6GW>P`9_fgah?708onm,B",
                @"\MBJC[]ZUV^DRQbcY;OdlekXmAHfNWFEGI<543=6:@P29>7?1`hjon_gia80,B",
            };

            var positionStats = new GameStateStats();

            var playStats = positionStats.GenerateStats(@"\MBJC[]ZUV^DRQb", gameArchive);

            Assert.IsNotNull(playStats['Y'.ToIndex()]);
            Assert.AreEqual(5, playStats['Y'.ToIndex()].SubsetCount);
            Assert.AreEqual(2, playStats['Y'.ToIndex()].BlackWins);

            Assert.IsNotNull(playStats['c'.ToIndex()]);
            Assert.AreEqual(2, playStats['c'.ToIndex()].SubsetCount);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var gameArchive    = File.ReadAllLines("ArchiveData.txt").ToList();
            var gameStateStats = new GameStateStats();

            var computerPlayers = new[] { new ComputerPlayer(), new ComputerPlayer() };

            var random = new Random();

            var depthFirstSearch = new DepthFirstSearch();

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            for (var i = 0; i < 500; i++)
            {
                var gameManager = new GameManager();

                Console.WriteLine("Game {0} ", i);

                var score = 0;
                for (var round = 0; round < 2; round++)
                {
                    Console.WriteLine("Round {0}", round);

                    PlayGame(gameManager, gameStateStats, gameArchive, depthFirstSearch, computerPlayers);

                    score += GetScore(round, gameManager);

                    Console.WriteLine("Score {0} ", score);
                    //Console.WriteLine(gameManager.GameOverMessage);

                    SwapPlayers(computerPlayers);
                }

                short winner;
                if (score == 0)
                {
                    winner = (short)random.Next(1);
                }
                else if (score > 0)
                {
                    winner = 1;
                }
                else
                {
                    winner = 0;
                }

                Console.WriteLine("Time {0}", stopWatch.Elapsed);

                computerPlayers[winner].Draw();
                Console.WriteLine();

                ChangeWeightsForSelectedPlayer(winner, computerPlayers, random);

                SwapPlayers(computerPlayers);

                stopWatch.Restart();
            }

            Console.ReadKey();
        }