コード例 #1
0
        static void Main(string[] args)
        {
            AllianceScenario allianceScenario = AllianceScenario.GetRandomAllianceScenario();
            Board            board            = Board.GetInitialBoard();
            BoardMove        moves            = new BoardMove();

            moves.Add(board.GetMove("ber", "kie"));
            moves.Add(board.GetMove("bud", "rum"));
            moves.Add(board.GetMove("con", "bul"));
            moves.Add(board.GetMove("lvp", "edi"));
            moves.Add(board.GetMove("mar", "pie"));
            moves.Add(board.GetMove("mos", "stp"));
            moves.Add(board.GetMove("mun", "ruh"));
            moves.Add(board.GetMove("par", "gas"));
            moves.Add(board.GetMove("rom", "nap"));
            moves.Add(board.GetMove("ven", "tyr"));
            moves.Add(board.GetMove("vie", "tri"));
            moves.Add(board.GetMove("war", "sil"));
            moves.Add(board.GetMove("ank", "con"));
            moves.Add(board.GetMove("bre", "mao"));
            moves.Add(board.GetMove("edi", "nth"));
            moves.Add(board.GetMove("kie", "den"));
            moves.Add(board.GetMove("lon", "eng"));
            moves.Add(board.GetMove("nap", "tys"));
            moves.Add(board.GetMove("sev", "bla"));
            moves.Add(board.GetMove("stp_sc", "bot"));
            moves.Add(board.GetMove("tri", "alb"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();


            moves.Clear();
            moves.Add(board.GetMove("bul", "gre"));
            moves.Add(board.GetMove("gas", "spa"));
            moves.Add(board.GetMove("kie", "hol"));
            moves.Add(board.GetMove("ruh", "bel"));
            moves.Add(board.GetMove("smy", "arm"));
            moves.Add(board.GetMove("stp", "nwy"));
            moves.Add(board.GetMove("tri", "ser"));
            moves.Add(board.GetMove("bot", "swe"));
            moves.Add(board.GetMove("con", "bul_ec"));
            moves.Add(board.GetMove("mao", "por"));
            moves.Add(board.GetMove("tys", "tun"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();

            //var boardMoves = BoardFutures.GetAllBoardMovesWinter(board);
            var          probabilisticFuturesAlgorithm = new ProbabilisticFuturesAlgorithm();
            int          limit        = 20;
            List <Board> futureBoards = board.GetFutures(allianceScenario, probabilisticFuturesAlgorithm);

            while (futureBoards.Any() && limit > 0)
            {
                limit--;
                board        = futureBoards[0];
                futureBoards = board.GetFutures(allianceScenario, probabilisticFuturesAlgorithm);
            }
        }
コード例 #2
0
ファイル: BoardTests.cs プロジェクト: vfridell/Diplomacy
        public void BoardCloneTest()
        {
            Board board = Board.GetInitialBoard();
            Board clone = board.Clone();

            Assert.AreEqual(clone.OwnedSupplyCenters[Powers.Germany].Count, board.OwnedSupplyCenters[Powers.Germany].Count);

            BoardMove moves = new BoardMove();

            moves.Add(clone.GetMove("kie", "den"));
            moves.Add(clone.GetMove("ber", "kie"));
            moves.FillHolds(clone);
            clone.ApplyMoves(moves);
            clone.EndTurn();

            Assert.AreNotEqual(clone.Turn, board.Turn);

            moves.Clear();
            moves.Add(clone.GetMove("kie", "hol"));
            moves.FillHolds(clone);
            clone.ApplyMoves(moves);
            clone.EndTurn();

            Assert.AreNotEqual(clone.OwnedSupplyCenters[Powers.Germany].Count, board.OwnedSupplyCenters[Powers.Germany].Count);
        }
コード例 #3
0
ファイル: MoveTests.cs プロジェクト: vfridell/Diplomacy
        public void DisbandWinterUnitMoves()
        {
            Board     board = Board.GetInitialBoard();
            BoardMove moves = new BoardMove();

            moves.Add(board.GetMove("tri", "ven"));
            moves.Add(board.GetMove("ven", "pie"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();


            moves.Clear();
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();

            Assert.AreEqual(2, board.OwnedSupplyCenters[Powers.Italy].Count);
            Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Austria].Count);
            Assert.AreEqual(22, board.OwnedSupplyCenters.Where(kvp => kvp.Key != Powers.None).SelectMany(kvp => kvp.Value).Count());

            var unitMoves = board.GetUnitMoves();

            Assert.AreEqual(2, unitMoves.Count(um => um.IsBuild));
            Assert.AreEqual(3, unitMoves.Count(um => um.IsDisband));
        }
コード例 #4
0
ファイル: MoveTests.cs プロジェクト: vfridell/Diplomacy
        public void BuildUnitMoves()
        {
            Board     board = Board.GetInitialBoard();
            BoardMove moves = new BoardMove();

            moves.Add(board.GetMove("kie", "den"));
            moves.Add(board.GetMove("ber", "kie"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count);
            board.EndTurn();

            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count);

            moves.Clear();
            moves.Add(board.GetMove("kie", "hol"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count);
            board.EndTurn();

            Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(24, board.OwnedSupplyCenters.Where(kvp => kvp.Key != Powers.None).SelectMany(kvp => kvp.Value).Count());

            var unitMoves = board.GetUnitMoves();

            Assert.AreEqual(4, unitMoves.Count(um => um.IsBuild));
        }
コード例 #5
0
ファイル: MoveTests.cs プロジェクト: vfridell/Diplomacy
        public void OwnedSupplyCentersOwnershipSwitch()
        {
            Board     board = Board.GetInitialBoard();
            BoardMove moves = new BoardMove();

            moves.Add(board.GetMove("par", "pic"));
            moves.Add(board.GetMove("mun", "bur"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.France].Count);
            board.EndTurn();

            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.France].Count);

            moves.Clear();
            moves.Add(board.GetMove("bur", "par"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.France].Count);
            board.EndTurn();

            Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(2, board.OwnedSupplyCenters[Powers.France].Count);
            Assert.AreEqual(22, board.OwnedSupplyCenters.Where(kvp => kvp.Key != Powers.None).SelectMany(kvp => kvp.Value).Count());
        }
コード例 #6
0
        public void GenerateWinterMovesNoEmptyBuilds()
        {
            Board     board = Board.GetInitialBoard();
            BoardMove moves = new BoardMove();

            moves.Add(board.GetMove("tri", "ven"));
            moves.Add(board.GetMove("ven", "pie"));
            moves.Add(board.GetMove("ber", "kie"));
            moves.Add(board.GetMove("kie", "den"));
            moves.Add(board.GetMove("mun", "ruh"));
            moves.Add(board.GetMove("stp_sc", "bot"));
            moves.Add(board.GetMove("sev", "rum"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();


            moves.Clear();
            moves.Add(board.GetMove("bot", "swe"));
            moves.Add(board.GetMove("kie", "hol"));
            moves.Add(board.GetMove("ruh", "bel"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();

            Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Russia].Count);
            Assert.AreEqual(2, board.OwnedSupplyCenters[Powers.Italy].Count);
            Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Austria].Count);

            var boardMoves = BoardFutures.GetAllBoardMovesWinter(board);

            Assert.IsTrue(boardMoves.All(bm => null != bm.FirstOrDefault(um => um.Edge.Target == MapNodes.Get("mun"))));
            Assert.AreEqual(144, boardMoves.Count());

            //this is the total for when empty builds are included
            //Assert.AreEqual(1944, boardMoves.Count());
        }
コード例 #7
0
        public void GenerateWinterMovesAustriaOut1902()
        {
            Board     board = Board.GetInitialBoard();
            BoardMove moves = new BoardMove();

            moves.Add(board.GetMove("mun", "boh"));
            moves.Add(board.GetMove("ven", "tri"));
            moves.Add(board.GetMove("vie", "tyr"));
            moves.Add(board.GetMove("bud", "gal"));
            moves.Add(board.GetMove("tri", "alb"));
            moves.Add(board.GetMove("rom", "ven"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();


            moves.Clear();
            moves.Add(board.GetMove("ven", "tri"));
            moves.Add(board.GetMove("tri", "bud"));
            moves.Add(board.GetMove("boh", "vie"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();

            Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Russia].Count);
            Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.Italy].Count);
            Assert.AreEqual(0, board.OwnedSupplyCenters[Powers.Austria].Count);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Turkey].Count);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.England].Count);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.France].Count);

            var boardMoves = BoardFutures.GetAllBoardMovesWinter(board);

            Assert.IsTrue(boardMoves.All(bm => null != bm.FirstOrDefault(um => um.Edge.Target == MapNodes.Get("mun"))));
            Assert.IsTrue(boardMoves.All(bm => bm.Where(um => um.Unit.Power == Powers.Austria).All(um => um.IsDisband)));
            Assert.AreEqual(4, boardMoves.Count());
        }
コード例 #8
0
ファイル: MoveTests.cs プロジェクト: vfridell/Diplomacy
        public void BuildUnitMovesArmyNoNcSc()
        {
            Board     board = Board.GetInitialBoard();
            BoardMove moves = new BoardMove();

            moves.Add(board.GetMove("tri", "ven"));
            moves.Add(board.GetMove("ven", "pie"));
            moves.Add(board.GetMove("ber", "kie"));
            moves.Add(board.GetMove("kie", "den"));
            moves.Add(board.GetMove("mun", "ruh"));
            moves.Add(board.GetMove("stp_sc", "bot"));
            moves.Add(board.GetMove("sev", "rum"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();


            moves.Clear();
            moves.Add(board.GetMove("bot", "swe"));
            moves.Add(board.GetMove("kie", "hol"));
            moves.Add(board.GetMove("ruh", "bel"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();

            Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Russia].Count);
            Assert.AreEqual(2, board.OwnedSupplyCenters[Powers.Italy].Count);
            Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Austria].Count);

            var unitMoves = BoardFutures.GetWinterUnitMoves(board);

            Assert.IsFalse(unitMoves.Any(um => um.IsBuild &&
                                         um.Unit.UnitType == UnitType.Army &&
                                         um.Edge.Target.ShortName.Contains("_nc")));
        }
コード例 #9
0
        public void GenerateWinterMovesCorrectNumberOfBuildsPerPower()
        {
            Board     board = Board.GetInitialBoard();
            BoardMove moves = new BoardMove();

            moves.Add(board.GetMove("ber", "kie"));
            moves.Add(board.GetMove("bud", "rum"));
            moves.Add(board.GetMove("con", "bul"));
            moves.Add(board.GetMove("lvp", "edi"));
            moves.Add(board.GetMove("mar", "pie"));
            moves.Add(board.GetMove("mos", "stp"));
            moves.Add(board.GetMove("mun", "ruh"));
            moves.Add(board.GetMove("par", "gas"));
            moves.Add(board.GetMove("rom", "nap"));
            moves.Add(board.GetMove("ven", "tyr"));
            moves.Add(board.GetMove("vie", "tri"));
            moves.Add(board.GetMove("war", "sil"));
            moves.Add(board.GetMove("ank", "con"));
            moves.Add(board.GetMove("bre", "mao"));
            moves.Add(board.GetMove("edi", "nth"));
            moves.Add(board.GetMove("kie", "den"));
            moves.Add(board.GetMove("lon", "eng"));
            moves.Add(board.GetMove("nap", "tys"));
            moves.Add(board.GetMove("sev", "bla"));
            moves.Add(board.GetMove("stp_sc", "bot"));
            moves.Add(board.GetMove("tri", "alb"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();


            moves.Clear();
            moves.Add(board.GetMove("bul", "gre"));
            moves.Add(board.GetMove("gas", "spa"));
            moves.Add(board.GetMove("kie", "hol"));
            moves.Add(board.GetMove("ruh", "bel"));
            moves.Add(board.GetMove("smy", "arm"));
            moves.Add(board.GetMove("stp", "nwy"));
            moves.Add(board.GetMove("tri", "ser"));
            moves.Add(board.GetMove("bot", "swe"));
            moves.Add(board.GetMove("con", "bul_ec"));
            moves.Add(board.GetMove("mao", "por"));
            moves.Add(board.GetMove("tys", "tun"));
            moves.FillHolds(board);
            board.ApplyMoves(moves);
            board.EndTurn();

            Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Germany].Count);
            Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Russia].Count);
            Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Italy].Count);
            Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.Austria].Count);
            Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.Turkey].Count);
            Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.England].Count);
            Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.France].Count);

            var boardMoves = BoardFutures.GetAllBoardMovesWinter(board);

            Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Germany) == 6));
            Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Russia) == 6));
            Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Italy) == 4));
            Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Austria) == 5));
            Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Turkey) == 5));
            Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.England) == 3));
            Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.France) == 5));

            //this is the total for when empty builds are included
            //Assert.AreEqual(1944, boardMoves.Count());
        }