Exemplo n.º 1
0
        static void Main(string[] args)
        {
            GameMaster master = new GameMaster("Master");

            master.OutputActionEvent += OutputAction;

            var p1 = new Player("Kondo");

            p1.OutputActionEvent += OutputAction;
            master.AddPlayer(p1);

            var p2 = new Player("Ookura");

            p2.OutputActionEvent += OutputAction;
            master.AddPlayer(p2);

            var p3 = new Player("Yamazaki");

            p3.OutputActionEvent += OutputAction;
            master.AddPlayer(p3);

            var p4 = new Player("Nakazawa");

            p4.OutputActionEvent += OutputAction;
            master.AddPlayer(p4);

            var sim = new GameSimulator(master);

            sim.RunSimSync();

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length <= 1)
            {
                Console.WriteLine("Please provide at least two players as console arguments.");
                Console.WriteLine("Player can either be human or bot dll.");
                Console.WriteLine("Example with 4 Players: dotnet run -- BasicBot.dll human human BasicBot.dll");
                return;
            }

            var multiGameListener = new MultiGameListener();
            // multiGameListener.AddGameListener(new ConsoleGameOutput());
            var gameMaster   = new GameMaster(multiGameListener);
            int playerNumber = 0;

            foreach (var arg in args)
            {
                ++playerNumber;
                Object player;
                if (arg.ToLower() == "human")
                {
                    player = new ConsolePlayerController();
                }
                else
                {
                    player = LoadBotFromAssembly(Path.GetFullPath(arg));
                }
                multiGameListener.AddGameListener((IGameListener)player);
                gameMaster.AddPlayer(new Player("Player", (IPlayerController)player));
                Console.WriteLine(player.GetType().Name + " is Player " + playerNumber);
            }
            int[]     playerStats = new int[playerNumber + 1];
            const int numGames    = 100000;

            for (var i = 0; i < numGames; ++i)
            {
                var loosingPlayer = gameMaster.StartGame();
                if (loosingPlayer >= 0)
                {
                    playerStats[loosingPlayer] += 1;
                }
                else
                {
                    playerStats[playerNumber] += 1;
                }
                var progress = (i / (double)numGames) * 100;
                if (progress % 10 == 0)
                {
                    Console.WriteLine(progress + "%");
                }
            }
            Console.WriteLine("Ties: {0}", (playerStats[playerNumber] / (double)numGames) * 100);
            for (int i = 0; i < playerStats.Length - 1; i++)
            {
                Console.WriteLine("Player {0} loose rate of {1}%", i + 1, (playerStats[i] / (double)numGames) * 100);
            }
        }
Exemplo n.º 3
0
        public void GameMaster_Start()
        {
            GameMaster gm = new GameMaster((GameContext)ContextFactory.CreateGameContext());

            gm.AddPlayer(p1);
            gm.AddPlayer(p2);

            object[] testCallbacks =
            {
                p1, "Start",            0, 0,
                p2, "Start",            0, 0,
                p1, "CardDistributed",  5, 0,
                p2, "CardDistributed",  5, 0,
                p1, "CardDistributed", 10, 0,
                p2, "CardDistributed", 10, 0,
                p1, "CardDistributed", 15, 0,
                p2, "CardDistributed", 15, 0,
                p1, "CardDistributed", 20, 0,
                p2, "CardDistributed", 20, 0,
                p1, "CardDistributed", 25, 0,
                p2, "CardDistributed", 25, 0,
                p1, "CardDistributed", 27, 0,
                p2, "CardDistributed", 26, 0,
                p1, "CardDistributed", 27, 0,
                p2, "CardDistributed", 26, 0,
            };
            int p = 0;

            p1.callback = (player, methodName, pctx) => {
                Debug.WriteLine("[{0}] {1} cards={2}", player.Name, methodName, pctx.Deck.ToCardsetString());
                Assert.AreEqual(testCallbacks[p++], player);
                Assert.AreEqual(testCallbacks[p++], methodName);
                Assert.AreEqual(testCallbacks[p++], pctx.Deck.Count());
                Assert.AreEqual(testCallbacks[p++], pctx.GameContext.Ba.Count());
            };

            p2.callback = p1.callback;

            // スタート
            gm.Start();
        }
Exemplo n.º 4
0
        public void GameMaster_getFirstDealer()
        {
            GameContext ctx = (GameContext)ContextFactory.CreateGameContext();
            GameMaster  gm  = new GameMaster(ctx);

            gm.AddPlayer(p1);
            gm.AddPlayer(p2);

            p1.callback = p2.callback = (player, methodName, pctx) =>
            {
                if (methodName == "ProcessTurn")
                {
                    Assert.IsTrue(pctx.Deck.ToCardsetString().Contains("S3"));
                }
            };

            p2.callback = p1.callback;

            // スタート
            gm.Start();
        }
Exemplo n.º 5
0
    public Rect zone;           //TODO : lire ces infos sur un objet unique dans la scene

    private void Start()
    {
        GameMaster.AddPlayer(this);
        rb         = GetComponent <Rigidbody2D>();
        nbJumps    = 2;
        nbJumpsMax = 2;
        runRatio   = 2.5f;
        animator   = model.GetComponent <Animator>();
        lives      = 5;
        ToggleAttackTriggers(false);
        isDescending = false;
    }
Exemplo n.º 6
0
        /// <summary>
        /// ゲーム開始
        /// </summary>
        private void StartGame()
        {
            if (!CanStartGame())
            {
                return;
            }

            GameHistory.Clear();

            var master = new GameMaster(MasterName);

            master.OutputActionEvent += OutputParsonAction;

            foreach (var name in PlayerList)
            {
                var player = new Player(name);

                player.OutputActionEvent += OutputParsonAction;

                master.AddPlayer(player);
            }

            Sim = new GameSimulator(master, () =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    IsGamePlaying = false;
                    Sim           = null;
                    RaiseCommandCanExecute();
                });
            });

            Sim.RunSimAsync();
            IsGamePlaying = true;
            RaiseCommandCanExecute();
        }
Exemplo n.º 7
0
        public void GameMaster_PutCard_p1win()
        {
            var        ctx = (GameContext)ContextFactory.CreateGameContext();
            GameMaster gm  = new GameMaster(ctx)
            {
                wait_msec = 0
            };

            gm.AddPlayer(p1);
            gm.AddPlayer(p2);

            int checkTeban = -1;

            // 手札を切る関数
            Action <IGamePlayer, IPlayerContext>[] procs =
            {
                (player, pctx) => { checkTeban = pctx.GameContext.Teban; gm.PutCards(player, new[] { pctx.Deck.ElementAt(0) }); },
                (player, pctx) => { gm.PutCards(player, null); },
            };

            string[] testCallbacks =
            {
                "Agari",
                "Agari",
                "Finish",
                "Finish",
            };

            bool complete = false;

            int p = 0, procp = 0;
            int count = 0;

            p1.callback = p2.callback = (player, mn, pctx) =>
            {
                var n = player.Name;
                Debug.WriteLine("{3}, [{0}] {1} cards={2}", n, mn, pctx.Deck.ToCardsetString(), ++count);
                lock (gm) try
                    {
                        if (mn == "CardDistributed" || mn == "CardSwapped" || mn == "Start" ||
                            mn == "Nagare" || mn == "CardsArePut" || mn == "Thinking")
                        {
                            return;
                        }

                        if (mn == "ProcessTurn")
                        {
                            procs[procp++ % procs.Length](player, pctx);
                            return;
                        }
                        else if (mn == "Nagare")
                        {
                            Assert.AreEqual(0, pctx.GameContext.Yama);
                            Assert.AreEqual(checkTeban, pctx.GameContext.Teban);
                            //Assert.AreEqual(checkTeban, pctx.GameContext.LastPutPlayerNum);
                            return;
                        }

                        Assert.AreEqual(testCallbacks[p++], mn);
                        Assert.AreEqual(checkTeban, pctx.GameContext.Teban);
                        //Assert.AreEqual(checkTeban, pctx.GameContext.LastPutPlayerNum);

                        if (mn == "Finish")
                        {
                            for (int i = 0; i < ctx.PlayerInfo.Count(); i++)
                            {
                                if (i == checkTeban)
                                {
                                    Assert.AreEqual(1, ctx.PlayerInfo.ElementAt(i).OrderOfFinish);
                                    Assert.AreEqual(PlayerRank.DAIFUGO, ctx.PlayerInfo.ElementAt(i).Ranking);
                                }
                                else
                                {
                                    Assert.AreEqual(2, ctx.PlayerInfo.ElementAt(i).OrderOfFinish);
                                    Assert.AreEqual(PlayerRank.DAIHINMIN, ctx.PlayerInfo.ElementAt(i).Ranking);
                                }
                            }
                        }
                        if (p == testCallbacks.Count())
                        {
                            // 完走した。
                            Debug.WriteLine("Test Complete. p=" + p);
                            complete = true;
                        }
                    }
                    catch (Exception e) { Debug.WriteLine(e); throw; }
            };

            // スタート
            gm.Start();

            for (int i = 0; i < 10 && !complete; i++)
            {
                System.Threading.Thread.Sleep(500);
            }
            Assert.IsTrue(complete);
        }
Exemplo n.º 8
0
        public void GameMaster_PutCard_Nagare3()
        {
            var        ctx = (GameContext)ContextFactory.CreateGameContext();
            GameMaster gm  = new GameMaster(ctx);

            gm.AddPlayer(p2);
            gm.AddPlayer(p1);
            gm.AddPlayer(p3);

            string[] testCallbacks =
            {
                "Thinking",
                "Thinking",
                "Thinking",
                "ProcessTurn",   // 手番のプレイヤーがカードを出す
                "Thinking",
                "Thinking",
                "Thinking",
                "ProcessTurn",   // 次のプレイヤーがパスする
                "Thinking",
                "Thinking",
                "Thinking",
                "ProcessTurn",   // 次のプレイヤーがパスする
                "Nagare",        // 流れ通知がくる
                "Nagare",        // 流れ通知がくる
                "Nagare",        // 流れ通知がくる
                "Thinking",
                "Thinking",
                "Thinking",
                "ProcessTurn",   // 手番のプレイヤーがカードを出す
                "Thinking",
                "Thinking",
                "Thinking",
                "ProcessTurn",   // 次のプレイヤーがパスする
                "Thinking",
                "Thinking",
                "Thinking",
                "ProcessTurn",   // 次のプレイヤーがパスする
                "Nagare",        // 流れ通知がくる
                "Nagare",        // 流れ通知がくる
                "Nagare",        // 流れ通知がくる
                "Thinking",
                "Thinking",
                "Thinking",
                "ProcessTurn",
            };

            bool   complete    = false;
            int    p           = 0;
            int    count       = 0;
            object checkPlayer = null; // 流れた後、手番がまわることになるプレイヤー
            object checkTeban  = null; // 流れた後の手番

            p1.callback = p2.callback = p3.callback = (player, mn, pctx) =>
            {
                lock (testCallbacks) try
                    {
                        count++;
                        var n = player.Name;
                        Debug.WriteLine("{3}, [{0}] {1} cards={2}", n, mn, pctx.Deck.ToCardsetString(), count);

                        if (mn == "CardDistributed" || mn == "CardSwapped" || mn == "Start" || mn == "CardsArePut")
                        {
                            return;
                        }

                        Assert.AreEqual(testCallbacks[p++], mn);

                        if (mn == "ProcessTurn")
                        {
                            if (p == 4)
                            {
                                gm.PutCards(player, new[] { pctx.Deck.ElementAt(0) });
                                checkTeban  = ctx.Teban;
                                checkPlayer = player;
                            }
                            else if (p == 19 || p == 34)
                            {
                                Assert.AreEqual(checkTeban, ctx.Teban);
                                Assert.AreEqual(checkPlayer, player);
                                gm.PutCards(player, new[] { pctx.Deck.ElementAt(0) });
                                checkTeban  = ctx.Teban;
                                checkPlayer = player;
                            }
                            else
                            {
                                var cx = pctx.GameContext.Ba;
                                Assert.AreEqual(1, cx.Count());
                                gm.PutCards(player, null);
                            }
                        }

                        if (mn == "Nagare")
                        {
                            var cx = pctx.GameContext.Ba;
                            Assert.AreEqual(0, cx.Count());
                        }
                        if (p == testCallbacks.Count())
                        {
                            // 完走した。
                            Debug.WriteLine("Test Complete. p=" + p);
                            complete = true;
                        }
                    }
                    catch (Exception e) { Debug.WriteLine(e); throw; }
            };

            // スタート
            gm.Start();

            for (int i = 0; i < 10 && !complete; i++)
            {
                System.Threading.Thread.Sleep(500);
            }
            Assert.IsTrue(complete);
        }
Exemplo n.º 9
0
        public void GameMaster_PutCard_Nagare()
        {
            var        ctx = (GameContext)ContextFactory.CreateGameContext();
            GameMaster gm  = new GameMaster(ctx);

            gm.AddPlayer(p1);
            gm.AddPlayer(p2);

            string[] testCallbacks =
            {
                "ProcessTurn",   // 手番のプレイヤーがカードを出す
                "ProcessTurn",   // 次のプレイヤーがパスする
                "Nagare",        // 流れ通知がくる
                "Nagare",        // 流れ通知がくる
                "ProcessTurn",   // 手番のプレイヤーがカードを出す
                "ProcessTurn",   // 次のプレイヤーがパスする
                "Nagare",        // 流れ通知がくる
                "Nagare",        // 流れ通知がくる
                "ProcessTurn",
            };

            int    p           = 0;
            int    count       = 0;
            object checkPlayer = null;
            object checkTeban  = null;

            p1.callback = p2.callback = (player, mn, pctx) =>
            {
                lock (testCallbacks)
                {
                    count++;
                    var n = player.Name;
                    Debug.WriteLine("{3}, [{0}] {1} cards={2}", n, mn, pctx.Deck.ToCardsetString(), count);

                    if (mn == "CardDistributed" || mn == "CardSwapped" || mn == "Start")
                    {
                        return;
                    }

                    Assert.AreEqual(testCallbacks[p++], mn);

                    if (mn == "ProcessTurn")
                    {
                        if (p == 1)
                        {
                            gm.PutCards(player, new[] { pctx.Deck.ElementAt(0) });
                            checkTeban  = ctx.Teban;
                            checkPlayer = player;
                        }
                        else if (p == 5)
                        {
                            Assert.AreEqual(checkPlayer, player);
                            Assert.AreEqual(checkTeban, ctx.Teban);
                            gm.PutCards(player, new[] { pctx.Deck.ElementAt(0) });
                            checkTeban  = ctx.Teban;
                            checkPlayer = player;
                        }
                        else
                        {
                            Assert.AreEqual(1, pctx.GameContext.Yama);
                            gm.PutCards(player, null);
                        }
                    }

                    if (mn == "Nagare")
                    {
                        Assert.AreEqual(0, pctx.GameContext.Yama);
                    }
                }
            };

            p2.callback = p1.callback;

            // スタート
            gm.Start();
        }
Exemplo n.º 10
0
        public void GameMaster_CardSwap()
        {
            GameContext ctx = (GameContext)ContextFactory.CreateGameContext();
            GameMaster  gm  = new GameMaster(ctx);

            gm.AddPlayer(p1);
            gm.AddPlayer(p2);

            object[] testCallbacks =
            {
                p1, "Start",        0, 0,
                p2, "Start",        0, 0,
                p2, "CardSwapped", 26, 0,
                p1, "CardSwapped", 27, 0,
            };

            int    p         = 0;
            int    count     = 0;
            string lastDeck1 = "";
            string lastDeck2 = "";

            p1.callback = p2.callback = (player, methodName, pctx) =>
            {
                count++;
                var n = player.Name;
                Debug.WriteLine("{3}, [{0}] {1} cards={2}", n, methodName, pctx.Deck.ToCardsetString(), count);

                if (count <= 2)
                {
                    if (n == p1.Name)
                    {
                        // プレイヤー1を大貧民にする
                        var pctxx = pctx as PlayerContext;
                        pctxx.Ranking = PlayerRank.DAIHINMIN;
                    }
                    else
                    {
                        // プレイヤー2を大富豪にする
                        var pctxx = pctx as PlayerContext;
                        pctxx.Ranking = PlayerRank.DAIFUGO;
                    }
                }


                if (methodName == "CardDistributed")
                {
                    if (n == p1.Name)
                    {
                        lastDeck1 = pctx.Deck.ToCardsetString();
                    }
                    else
                    {
                        lastDeck2 = pctx.Deck.ToCardsetString();
                    }
                    return;
                }

                if (p < testCallbacks.Length)
                {
                    p++; //Assert.AreEqual(testCallbacks[p++], player);
                    Assert.AreEqual(testCallbacks[p++], methodName);
                    p++; // Assert.AreEqual(testCallbacks[p++], pctx.Deck.Count());
                    Assert.AreEqual(testCallbacks[p++], pctx.GameContext.Ba.Count());
                }

                if (methodName == "CardSwapped")
                {
                    Assert.AreNotEqual((n == p1.Name) ? lastDeck1 : lastDeck2, pctx.Deck.ToCardsetString());
                }
            };

            // スタート
            gm.Start();
        }