Exemplo n.º 1
0
        public void CondPiecesRemaining()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (option ""pass turn"" true)" +
                @" (board (boardgrid33))" +
                @" (piece (piece1))" +
                @" (piece (piece2))" +
                @" (board-setup (X (man {0}) (chip {1})) (O (man B-3)) )" +
                @" (win-condition (tot-pce-cond)) )";
            var matrix = new string[, ] {
                { "A-1            ,       ", "-,None" },
                { "A-1 B-1        ,       ", "X,Win" },
                { "A-1 B-1 C-1    ,       ", "-,None" },
                { "A-1 B-1 C-1 C-2,       ", "-,None" },
                { "A-1 B-1        ,C-3    ", "-,None" },
                { "A-1            ,C-3 C-2", "X,Win" },
                { "               ,C-3 C-2", "X,Win" },
                { "A-1 B-1 C-1    ,C-3    ", "-,None" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var setups = matrix[i, 0].Split(',');
                var tp     = String.Format(testprog, setups[0], setups[1]);
                //var tp = String.Format(testprog, matrix[i, 0], matrix[i, 1]);
                var game = PolyGame.CreateInner("bs1", new StringReader(tp));
                game.MakeMove(0);
                var expecteds = matrix[i, 1].SplitXY();
                Assert.AreEqual(expecteds[0], game.ResultPlayer.ToString(), matrix[i, 0]);
                Assert.AreEqual(expecteds[1], game.GameResult.ToString(), matrix[i, 0]);
            }
        }
Exemplo n.º 2
0
        static PlayWrapper CreateTestGame(string text, int level = -1)
        {
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (title ""movetype"")" +
                @" (players X O)" +
                @" (turn-order X (X MT1) O (O MT2))" +
                @" (board (boardgrid33))" +
                @" (board-setup (X (man A-1)) (O (man A-2)) )" +
                @" (piece (name man) {0})" +
                @")";

            var matrix = new string[, ] {
                { "(drops (A-1 s add)) (moves (A-1 s add))", "" },
                //{ "(moves (s add) (move-type mt1) (se add) (move-type mt2) (sw add) )", "X,A-1,B-1;X,B-1,B-2;O,A-2,B-2;O,B-2,B-1" },
            };

            if (level >= 0)
            {
                Logger.Level = level;
            }
            PolyGame game = null;

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var script = String.Format(testprog, matrix[i, 0]);
                game = PolyGame.CreateInner("cwld", new StringReader(script), 0);
                var splits = matrix[i, 1].SplitXY();
                var moves  = game.LegalMoves;
            }
            return(new PlayWrapper {
                Player = ConsolePlayer.Create(game, 0)
            });
        }
Exemplo n.º 3
0
        public void GameTranslate()
        {
            Logger.Open(1);
            var testprog =
                @"(translate" +
                @" (""White"" ""Blanc"")" +
                @" (""Black"" ""Noir"")" +
                @" (""Day"" ""Night"") )" +
                @"(game" +
                @" (title ""trans1"")" +
                @" (players X O)" +
                @" (turn-order X O)" +
                @" (board)" +
                @")";
            var matrix = new string[, ] {
                { "", "" }
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("tr1", new StringReader(tp));
                Assert.IsNotNull(game, PolyGame.LastError);
                Assert.AreEqual("trans1", game.Title);
                Assert.AreEqual("O,X", game.Players.OrderBy(s => s).Join());
            }
        }
Exemplo n.º 4
0
        public void BoardPiece1()
        {
            Logger.Open(1);
            var input = new StringReader(
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @"(board (boardgrid45))" +
                @"(piece (piece1)) )");
            var game = PolyGame.CreateInner("bt2", input);

            var piece_exp = new string[] {
                "man;M;man desc;man help;False"
            };
            var piece_act = game.Pieces
                            .Select(p => Util.Join(";", p.Name, p.Notation, p.Description, p.Help, p.IsDummy));

            CheckEqual(piece_exp, piece_act);

            var image_exp = new string[] {
                "man;X;MANX.png",
                "man;O;MANO.png",
            };
            var image_act = game.PieceImages
                            .Select(p => Util.Join(";", p.Piece, p.Player, p.Images.Join(",")));

            CheckEqual(image_exp, image_act);
        }
Exemplo n.º 5
0
        public void MoveUndoRedo()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid45))" +
                @" (board-setup (X (man off 2 C-1)) (O (man off 2 B-1)))" +
                @" (piece (name man) (drops ((verify empty?) add)))" +
                @")";

            var matrix = new string[, ] {
                { "", "X;B-1,O,man,;C-1,X,man," },
                { "M", "O;A-1,X,man,;B-1,O,man,;C-1,X,man," },
                { "MM", "X;A-1,X,man,;A-2,O,man,;B-1,O,man,;C-1,X,man," },
                { "MMM", "O;A-1,X,man,;A-2,O,man,;A-3,X,man,;B-1,O,man,;C-1,X,man," },

                { "MU", "X;B-1,O,man,;C-1,X,man," },
                { "MMUU", "X;B-1,O,man,;C-1,X,man," },
                { "MUMU", "X;B-1,O,man,;C-1,X,man," },

                { "MUMUM", "O;A-1,X,man,;B-1,O,man,;C-1,X,man," },
                { "MMU", "O;A-1,X,man,;B-1,O,man,;C-1,X,man," },
                { "MMMUUUM", "O;A-1,X,man,;B-1,O,man,;C-1,X,man," },

                { "MUR", "O;A-1,X,man,;B-1,O,man,;C-1,X,man," },
                { "MMUURR", "X;A-1,X,man,;A-2,O,man,;B-1,O,man,;C-1,X,man," },
                { "MMMUUURRR", "O;A-1,X,man,;A-2,O,man,;A-3,X,man,;B-1,O,man,;C-1,X,man," },

                { "MMUMURS", "X;B-1,O,man,;C-1,X,man," },
                { "MMUMURSM", "O;A-1,X,man,;B-1,O,man,;C-1,X,man," },

                { "MMUUU", "X;B-1,O,man,;C-1,X,man," },
                { "MMURRUU", "X;B-1,O,man,;C-1,X,man," },
                { "MMSMUU", "X;B-1,O,man,;C-1,X,man," },
            };
            var action = new Dictionary <char, Action <PolyGame> > {
                { 'M', g => g.MakeMove(0) },
                { 'U', g => g.UndoMove() },
                { 'R', g => g.RedoMove() },
                { 'S', g => g.Restart() },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var game = PolyGame.CreateInner("undoredo", new StringReader(testprog));
                foreach (var ch in matrix[i, 0])
                {
                    action[ch](game);
                }
                var result = game.TurnPlayer + ";" + game.PlayedPieces
                             .Select(p => Util.Join(",", p.Position, p.Player, p.Piece, p.Flags))
                             .OrderBy(s => s).Join(";");
                Assert.AreEqual(matrix[i, 1], result, matrix[i, 0]);
            }
        }
Exemplo n.º 6
0
        public void CondAbsConfOccupier()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (option ""pass turn"" true)" +
                @" (board (boardgrid45))" +
                @" (piece (piece1))" +
                @" (piece (piece2))" +
                @" (board-setup (X (man A-1 A-2)) (O (chip C-3)) )" +
                @" (win-condition (X O) (absolute-config {0}))" +
                @")";
            var matrix = new string[, ] {
                { "man (A-5)                    ", "-,None" },
                //{ "man A-5                      ", "-,None" },  -- TODO
                { "man (A-1)                    ", "X,Win" },
                { "man (A-2)                    ", "X,Win" },
                { "man (A-1 A-2 A-3)            ", "-,None" },
                { "man (A-1 A-2 C-3)            ", "-,None" },

                { "(not man) (A-1)              ", "O,Win" },
                { "(not man) (A-4)              ", "X,Win" },
                { "(not man) (C-3)              ", "X,Win" },

                { "(opponent man) (A-1)         ", "O,Win" },
                { "(opponent man) (A-2)         ", "O,Win" },
                { "(opponent chip) (A-1)        ", "-,None" },
                { "(opponent chip) (C-3)        ", "X,Win" },

                { "(not (opponent man)) (A-1)   ", "X,Win" },
                { "(not (opponent man)) (A-2)   ", "X,Win" },
                { "(not (opponent chip)) (A-1)  ", "X,Win" },
                { "(not (opponent chip)) (C-3)  ", "O,Win" },

                { "(any-owner man) (A-1)        ", "X,Win" },
                { "(any-owner man) (A-2)        ", "X,Win" },
                { "(any-owner chip) (A-1)       ", "-,None" },
                { "(any-owner chip) (C-3)       ", "X,Win" },

                { "(not (any-owner man)) (A-1)  ", "-,None" },
                { "(not (any-owner man)) (A-2)  ", "-,None" },
                { "(not (any-owner chip)) (A-1) ", "X,Win" },
                { "(not (any-owner chip)) (C-3) ", "-,None" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("bs1", new StringReader(tp));
                game.MakeMove(0);
                var expecteds = matrix[i, 1].SplitXY();
                Assert.AreEqual(expecteds[0], game.ResultPlayer.ToString(), matrix[i, 0]);
                Assert.AreEqual(expecteds[1], game.GameResult.ToString(), matrix[i, 0]);
            }
        }
Exemplo n.º 7
0
        public void GameTest1()
        {
            Logger.Open(1);
            var game = PolyGame.CreateInner("testgame.poly");

            Assert.AreEqual(1, game.Menu.Count());
            Assert.AreEqual("testgame title", game.Title);
            CollectionAssert.AreEquivalent(new string[] { "X", "O" }, game.Players.ToArray());
            Assert.AreEqual("X", game.TurnPlayer);
        }
Exemplo n.º 8
0
        public void MoveAdd()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid45))" +
                @" (board-setup (X (man off 1 C-1) (chip off 1)) (O (man off 1 C-3) (chip off 1)) (N (chip D-1)) )" +
                @" (piece (name man) (moves {0}))" +
                @" (piece (name chip))" +
                @")";

            var matrix = new string[, ] {
                { "(e add)                      ", "Move,man,X,C-1,C-2" },
                { "(e (add chip))               ", "Move,chip,X,C-1,C-2" },
                { "(e (add man chip))           ", "Move,man,X,C-1,C-2;Move,chip,X,C-1,C-2" },
                { "(B-1 add)                    ", "Move,man,X,C-1,B-1" },

                { "(e add-copy)                 ", "Copy,man,X,C-1,C-2" },
                { "(e (add-copy chip))          ", "Copy,chip,X,C-1,C-2" },
                { "(e (add-copy man chip))      ", "Copy,man,X,C-1,C-2;Copy,chip,X,C-1,C-2" },
                { "(B-1 add-copy)               ", "Copy,man,X,C-1,B-1" },

                { "(s create n e add)           ", "Move,man,X,C-1,C-2;Drop,man,X,D-1," },
                { "(s (create O) n e add)       ", "Move,man,X,C-1,C-2;Drop,man,O,D-1," },
                { "(s (create chip) n e add)    ", "Move,man,X,C-1,C-2;Drop,chip,X,D-1," },
                { "(s (create O chip) n e add)  ", "Move,man,X,C-1,C-2;Drop,chip,O,D-1," },
                { "(s (create D-2) n e add)     ", "Move,man,X,C-1,C-2;Drop,man,X,D-2," },
                { "(s (create e) n e add)       ", "Move,man,X,C-1,C-2;Drop,man,X,D-2," },
                { "(s (create chip e) n e add)  ", "Move,man,X,C-1,C-2;Drop,chip,X,D-2," },
                { "(s (create O e) n e add)     ", "Move,man,X,C-1,C-2;Drop,man,O,D-2," },
                { "(s (create O chip e) n e add)", "Move,man,X,C-1,C-2;Drop,chip,O,D-2," },
                { "(B-1 create n e add)         ", "Move,man,X,C-1,A-2;Drop,man,X,B-1," },

                { "(e capture add)            ", "Move,man,X,C-1,C-2;Take,man,X,C-2," },
                { "(e e capture w add)        ", "Move,man,X,C-1,C-2;Take,man,X,C-3," },
                { "(e e e capture w w add)    ", "Move,man,X,C-1,C-2;Take,man,X,C-4," },
                { "(e (capture n) add)        ", "Move,man,X,C-1,C-2;Take,man,X,B-2," },
                { "(e (capture e) add)        ", "Move,man,X,C-1,C-2;Take,man,X,C-3," },
                { "((capture C-2) e add)      ", "Move,man,X,C-1,C-2;Take,man,X,C-2," },
                { "((capture C-3) e add)      ", "Move,man,X,C-1,C-2;Take,man,X,C-3," },
                { "(B-1 capture add)          ", "Move,man,X,C-1,B-1;Take,man,X,B-1," },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("movadd", new StringReader(tp));

                var result = game.LegalMoveParts
                             .Select(m => Util.Join(",", m.Kind, m.Piece, m.Player, m.Position, m.Final ?? "")).Join(";");
                Assert.AreEqual(matrix[i, 1], result, matrix[i, 0]);
            }
        }
Exemplo n.º 9
0
        public void GameIncl2()
        {
            Logger.Open(1);
            var input = new StringReader(
                @"(include ""testincl.poly"")" +
                @"(game2)");
            var game = PolyGame.CreateInner("testincl2", input);

            Assert.AreEqual(1, game.Menu.Count());
            Assert.AreEqual("testincl game2", game.Title);
            CollectionAssert.AreEquivalent(new string[] { "X", "O" }, game.Players.ToArray());
            Assert.AreEqual("X", game.TurnPlayer);
        }
Exemplo n.º 10
0
        public void CondWinLoseDraw()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid33))" +
                @" (piece (name man) (drops ((verify empty?) add)))" +
                @" (board-setup (X (man off 2 A-1 A-2 A-3)) (O (man off 1 B-1 B-2 B-3)) )" +
                @"({0})" +
                @")";
            var matrix = new string[, ] {
                { "win-condition  (X) (absolute-config man (A-2))", "X,Win" },
                { "loss-condition (X) (absolute-config man (A-2))", "X,Loss" },
                { "draw-condition (X) (absolute-config man (A-2))", "-,Draw" },

                { "win-condition  (O) (absolute-config man (B-2))", "O,Win" },
                { "loss-condition (O) (absolute-config man (B-2))", "O,Loss" },
                { "draw-condition (O) (absolute-config man (B-2))", "-,Draw" },

                { "win-condition  (X) (absolute-config man (C-1))", "X,Win" },
                { "loss-condition (X) (absolute-config man (C-1))", "X,Loss" },
                { "draw-condition (X) (absolute-config man (C-1))", "-,Draw" },

                { "win-condition  (O) (absolute-config man (C-2))", "-,None;O,Win" },
                { "loss-condition (O) (absolute-config man (C-2))", "-,None;O,Loss" },
                { "draw-condition (O) (absolute-config man (C-2))", "-,None;-,Draw" },
                { "win-condition  (X) (absolute-config man (C-3))", "-,None;-,None;X,Win" },
                { "loss-condition (X) (absolute-config man (C-3))", "-,None;-,None;X,Loss" },
                { "draw-condition (X) (absolute-config man (C-3))", "-,None;-,None;-,Draw" },
                { "win-condition  (X) (absolute-config man (B-1))", "-,None;-,None;-,Draw" },
                { "loss-condition (X) (absolute-config man (B-1))", "-,None;-,None;-,Draw" },
                { "draw-condition (X) (absolute-config man (B-1))", "-,None;-,None;-,Draw" },
                { "win-condition  (O) (absolute-config man (A-1))", "-,None;-,None;-,Draw" },
                { "loss-condition (O) (absolute-config man (A-1))", "-,None;-,None;-,Draw" },
                { "draw-condition (O) (absolute-config man (A-1))", "-,None;-,None;-,Draw" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("cwld", new StringReader(tp));
                for (int j = 0; game.GameResult == ResultKinds.None; j++)
                {
                    game.MakeMove(0);
                    var expecteds = matrix[i, 1].SplitXY(j);
                    Assert.AreEqual(expecteds[0], game.ResultPlayer.ToString(), matrix[i, 0]);
                    Assert.AreEqual(expecteds[1], game.GameResult.ToString(), matrix[i, 0]);
                }
            }
        }
Exemplo n.º 11
0
        public void CondWinLoseDraw45()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (option ""pass turn"" true)" +
                @" (board (boardgrid45))" +
                @" (piece (piece1))" +
                @" (piece (piece2))" +
                @" (board-setup (X (man off 5 A-1 A-2)) (X (chip off 5 A-3)) (O (chip off 5 C-3)) )" +
                @" ({0})" +
                @")";
            var matrix = new string[, ] {
                { "win-condition  (X) (absolute-config man (B-1))", "-,None" },
                { "win-condition  (X) (absolute-config man (A-1))", "X,Win" },
                { "loss-condition (X) (absolute-config man (B-1))", "-,None" },
                { "loss-condition (X) (absolute-config man (A-1))", "X,Loss" },
                { "draw-condition (X) (absolute-config man (B-1))", "-,None" },
                { "draw-condition (X) (absolute-config man (A-1))", "-,Draw" },
                { "win-condition  (X) (absolute-config man (A-1 A-2))", "X,Win" },
                { "win-condition  (X) (absolute-config man (A-1 A-2 A-3))", "-,None" },

                { "win-condition  (X) (pieces-remaining 3 man)", "-,None" },
                { "win-condition  (X) (pieces-remaining 2 man)", "X,Win" },
                { "win-condition  (X) (pieces-remaining 1 man)", "-,None" },

                { "win-condition  (X) (pieces-remaining 3 chip)", "-,None" },
                { "win-condition  (X) (pieces-remaining 2 chip)", "-,None" },
                { "win-condition  (X) (pieces-remaining 1 chip)", "X,Win" },

                { "win-condition  (X) (pieces-remaining 3)", "X,Win" },
                { "win-condition  (X) (pieces-remaining 2)", "-,None" },
                { "win-condition  (X) (pieces-remaining 1)", "-,None" },

                { "count-condition (total-piece-count 3)", "-,None" },
                { "count-condition (total-piece-count 4)", "X,Win" },
                { "count-condition (total-piece-count 5)", "-,None" },
                //{ "count-condition stalemated)", "-,Draw" }, // BUG:compile error
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("cwld", new StringReader(tp));
                game.MakeMove(0);
                var expecteds = matrix[i, 1].SplitXY();
                Assert.AreEqual(expecteds[0], game.ResultPlayer.ToString(), matrix[i, 0]);
                Assert.AreEqual(expecteds[1], game.GameResult.ToString(), matrix[i, 0]);
            }
        }
Exemplo n.º 12
0
        public void GameMacro()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1) (board) {0}" +
                @"(define mac0 sub1)" +
                @"(define mac01 name sub1)" +
                @"(define macx $1)" +
                @"(define macax sub$1)" +
                @"(define macxa $1sub)" +
                @"(define macaxa sub$1sub)" +
                @"(define macb (piece (name sub1)) )" +
                @"(define macbx (piece (name sub$1)) )" +
                @"(define macxb (piece (name $1sub)) )" +
                @"(define macbxb (piece (name sub$1sub)) )" +
                @"(define macabcd (piece (name sub$1)) (piece (name sub$2)) (piece (name sub$3)) (piece (name sub$4)) )" +
                @"(define macs ""sub$1sub"")" +
                @")";
            var matrix = new string[, ] {
                { @"(piece (name sub1))", @"P,sub1" },
                { @"(piece ((mac01)))", @"P,sub1" },
                { @"(piece (name (mac0)))", @"P,sub1" },
                { @"(piece (name (macx xxx)))", @"P,xxx" },
                { @"(piece (name (macax xxx)))", @"P,subxxx" },
                { @"(piece (name (macxa xxx)))", @"P,xxxsub" },
                { @"(piece (name (macaxa xxx)))", @"P,subxxxsub" },
                { @"(macb)", @"P,sub1" },
                { @"(macbx xxx)", @"P,subxxx" },
                { @"(macxb xxx)", @"P,xxxsub" },
                { @"(macbxb xxx)", @"P,subxxxsub" },
                { @"(piece (name x)(help (macs xxx)))", @"H,subxxxsub" },
                { @"(macabcd x y z w)", @"P,subw subx suby subz" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp       = String.Format(testprog, matrix[i, 0]);
                var game     = PolyGame.CreateInner("cwld", new StringReader(tp), 0);
                var testkind = matrix[i, 1].SplitXY()[0];
                var expected = matrix[i, 1].SplitXY()[1];
                if (testkind == "P")
                {
                    Assert.AreEqual(expected, game.Pieces.Select(p => p.Name).Join(" "), matrix[i, 0]);
                }
                if (testkind == "H")
                {
                    Assert.AreEqual(expected, game.Pieces.Select(p => p.Help).Join(" "), matrix[i, 0]);
                }
            }
        }
Exemplo n.º 13
0
        public void MoveMoveType()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (title ""movetype"")" +
                @" (players X O)" +
                @" (turn-order {0})" +
                @" (board (boardgrid33))" +
                @" (board-setup (X (man A-1)) )" +
                @" (piece (name man) (moves {1}) )" +
                @")";

            var matrix = new string[, ] {
                { "X; (s add)", "X A-1 B-1" },
                { "X; (s add) (se add)", "X A-1 B-1; X A-1 B-2" },
                { "X;      (s add) (move-type mt) (se add)", "X A-1 B-1; X A-1 B-2" },
                { "X;      (s add) (s s add) (move-type mt) (se add)", "X A-1 B-1; X A-1 B-2; X A-1 C-1" },
                { "X;      (s add) (move-type mt) (s s add) (se add)", "X A-1 B-1; X A-1 B-2; X A-1 C-1" },
                // these test correct if move-type Any includes all others
                { "(X mt); (s add) (move-type mt) (se add)", "X A-1 B-2" },
                { "(X mt); (s add) (s s add) (move-type mt) (se add)", "X A-1 B-2" },
                { "(X mt); (s add) (move-type mt) (s s add) (se add)", "X A-1 B-2; X A-1 C-1" },
                // these test correct if move-type Any does NOT include all others
                //{ "X;      (s add) (move-type mt) (se add)",            "X A-1 B-1" },
                //{ "X;      (s add) (s s add) (move-type mt) (se add)",  "X A-1 B-1; X A-1 C-1" },
                //{ "X;      (s add) (move-type mt) (s s add) (se add)",  "X A-1 B-1" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var frags  = matrix[i, 0].Split(";");
                var script = String.Format(testprog, frags[0], frags[1]);
                var game   = PolyGame.CreateInner("movty", new StringReader(script));

                Assert.IsTrue(game.LegalMoveParts.All(m => m.Kind == MoveKinds.Move));
                Assert.IsTrue(game.LegalMoveParts.All(m => m.Piece == "man"));
                var actuals = game.LegalMoves
                              .Select(m => String.Join(" ", m.Player, m.Position1, m.Position2))
                              .OrderBy(s => s)
                              .Join("; ");
                Assert.AreEqual(matrix[i, 1], actuals, matrix[i, 0]);
                //var splits = matrix[i, 1].Split(";");
                //Assert.AreEqual(splits.Length, game.LegalMoves.Count, matrix[i,0]);
                //for (int j = 0; j < splits.Length; j++) {
                //  Assert.IsTrue(j < game.LegalMoves.Count, splits[j]);
                //  var move = game.LegalMoves[j];
                //  Assert.AreEqual(splits[j], String.Join(" ", move.Player, move.Position1, move.Position2), matrix[i, 0]);
                //}
            }
        }
Exemplo n.º 14
0
        public void BoardLink1()
        {
            Logger.Open(1);
            var input = new StringReader(
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @"(board (boardlink1)) )");
            var game = PolyGame.CreateInner("bt2", input);

            Assert.AreEqual(1, game.Menu.Count());
            Assert.AreEqual("stub1", game.Title);
            Assert.AreEqual("board1.png", game.BoardImages[0]);

            var positions = new PolyPosition[] {
                new PolyPosition {
                    Name = "a1", Location = Rect.Create(11, 12, 13, 14), IsDummy = false,
                },
                new PolyPosition {
                    Name = "a2", Location = Rect.Create(21, 22, 23, 24), IsDummy = false,
                },
                new PolyPosition {
                    Name = "b1", Location = Rect.Create(31, 32, 33, 34), IsDummy = false,
                },
                new PolyPosition {
                    Name = "b2", Location = Rect.Create(41, 42, 43, 44), IsDummy = false,
                },
            };

            CollectionAssert.AreEquivalent(positions, game.Positions.ToArray());

            var links = new PolyLink[] {
                new PolyLink {
                    Direction = "n", From = "a2", To = "a1"
                },
                new PolyLink {
                    Direction = "e", From = "a1", To = "b1"
                },
            };

            CollectionAssert.AreEquivalent(links, game.Links.ToArray());

            var zones = new PolyZone[] {
                new PolyZone {
                    Name = "zone1", Player = "X", Positions = "a1 a2"
                },
            };

            CollectionAssert.AreEquivalent(zones, game.Zones.ToArray());
        }
Exemplo n.º 15
0
        public void GameVariant()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid33))" +
                @" (history ""game history"")" +
                @" (piece (name man) (help ""man help"") (moves (n (create man) add)) )" +
                @")(variant (title ""var1"")" +
                @" {0}" +
                @")";
            var matrix = new string[, ] {
                { @"(description ""xxx"")",
                  @"var1,game history;man,man help" },
                { @"(default)",
                  @"var1,game history;man,man help" },
                { @"(history ""var1 history"") (piece (name man) (help ""varman help"") (moves (n (create man) add)) )",
                  @"var1,var1 history;man,varman help" },
                { @"(history ""var1 history"") (piece (name man2) (help ""varman2 help"") (moves (n (create man) add)) )",
                  @"var1,var1 history;man,man help;man2,varman2 help" },
                { @"(history ""var1 history"") (piece (name man2) (help ""varman2 help"") (moves (n (create man) add)) )" +
                  @" (piece (name man) (help ""varman help"") (moves (n (create man2) add)) )",
                  @"var1,var1 history;man,varman help;man2,varman2 help" },
                { @"(history ""var1 history"") (piece (name man) (help ""varman help"") (moves (n (create man2) add)) )" +
                  @" (piece (name man2) (help ""varman2 help"") (moves (n (create man) add)) )",
                  @"var1,var1 history;man,varman help;man2,varman2 help" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp        = String.Format(testprog, matrix[i, 0]);
                var game      = PolyGame.CreateInner("cwld", new StringReader(tp), 1);
                var expected0 = matrix[i, 1].SplitXY(0);
                Assert.AreEqual(expected0[0], game.Title, matrix[i, 0]);
                Assert.AreEqual(expected0[1], game.GetOption("history"), matrix[i, 0]);
                for (var j = 0; ; ++j)
                {
                    var expecteds = matrix[i, 1].SplitXY(j + 1);
                    if (expecteds == null)
                    {
                        break;
                    }
                    Assert.AreEqual(expecteds[0], game.Pieces[j].Name, matrix[i, 0]);
                    Assert.AreEqual(expecteds[1], game.Pieces[j].Help, matrix[i, 0]);
                }
            }
        }
Exemplo n.º 16
0
        public void DropControl()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @"(board (boardgrid45))" +
                @"(piece (piece1))" +
                @"(piece (piece2))" +
                @"(board-setup (X (man C-1) (xx off 1)) (O (man A-3) (xx off 1)) (N (chip D-1) (xx off 1)) )" +
                @"(piece (name xx) (drops {0}))" +
                @")";

            var matrix = new string[, ] {
                { "((if empty? else e add))                     ", "A-4 C-2 D-2" },
                { "((if friend? (while true e add)))            ", "C-2 C-3 C-4 C-5" },
                // or
                { "((if (or (piece? man) (piece? chip)) e add)) ", "A-4 C-2 D-2" },
                { "((if (or (piece? man w) (piece? chip w)) add))", "A-4 C-2 D-2" },
                // and
                { "((if (and not-empty? (not-empty? s)) e add)) ", "C-2" },
                { "((if (and true  (position? B-4)) add))       ", "B-4" },
                { "((if (and false (position? B-4)) add))       ", "" },
                { "((if (and (not true)  (position? B-4)) add)) ", "" },
                { "((if (and (not false) (position? B-4)) add)) ", "B-4" },
                // move flag
                { "((set-flag flg true)  (if (and (flag? flg) (position? B-4)) add))    ", "B-4" },
                { "((set-flag flg false) (if (and (flag? flg) (position? B-4)) add))    ", "" },
                { "((set-flag flg true)  (if (and (not-flag? flg) (position? B-4)) add))", "" },
                { "((set-flag flg false) (if (and (not-flag? flg) (position? B-4)) add))", "B-4" },
                // verify
                { "((verify friend?) e add)                     ", "C-2" },
                { "((verify false) e add)                       ", "" },
                { "((verify (not-on-board? e)) add)             ", "A-5 B-5 C-5 D-5" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("bs1", new StringReader(tp));

                Assert.IsTrue(game.LegalMoveParts.All(m => m.Kind == MoveKinds.Drop));
                Assert.IsTrue(game.LegalMoveParts.All(m => m.Piece == "xx"));
                Assert.IsTrue(game.LegalMoveParts.All(m => m.Player == "X"));
                var movestring = game.LegalMoveParts.Select(m => m.Position).OrderBy(m => m).Join(" ");
                Assert.AreEqual(matrix[i, 1], movestring, matrix[i, 0]);
            }
        }
Exemplo n.º 17
0
        public void MoveChange()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid45))" +
                @" (board-setup (X (man C-1)) (O (man C-3)) (N (chip D-1)) )" +
                @" (piece (name man) (moves {0}))" +
                @" (piece (name chip))" +
                @")";

            var matrix = new string[, ] {
                { "(e change-owner add)       ", "Move,man,X,C-1,C-2;Owner,man,X,C-2," },
                { "(s change-owner n e add)   ", "Move,man,X,C-1,C-2;Owner,man,X,D-1," },
                { "((change-owner n) e add)   ", "Move,man,X,C-1,C-2;Owner,man,X,B-1," },
                { "((change-owner s) e add)   ", "Move,man,X,C-1,C-2;Owner,man,X,D-1," },
                { "((change-owner D-2) e add) ", "Move,man,X,C-1,C-2;Owner,man,X,D-2," },
                { "((change-owner D-1) e add) ", "Move,man,X,C-1,C-2;Owner,man,X,D-1," },

                { "(e e change-owner e add)   ", "Move,man,X,C-1,C-4;Owner,man,X,C-3," },
                { "(s change-owner e add)     ", "Move,man,X,C-1,D-2;Owner,man,X,D-1," },

                { "(e flip add)               ", "Move,man,X,C-1,C-2;Owner,man,O,C-2," },
                { "(flip add)                 ", "Owner,man,O,C-1," },
                { "(flip e add)               ", "Move,man,X,C-1,C-2;Owner,man,O,C-1," }, // CHECK:???
                { "(s flip n e add)           ", "Move,man,X,C-1,C-2;Owner,man,O,D-1," },
                { "((flip n) e add)           ", "Move,man,X,C-1,C-2;Owner,man,O,B-1," },
                { "((flip s) e add)           ", "Move,man,X,C-1,C-2;Owner,man,O,D-1," },
                { "((flip D-2) e add)         ", "Move,man,X,C-1,C-2;Owner,man,O,D-2," },
                { "((flip D-1) e add)         ", "Move,man,X,C-1,C-2;Owner,man,O,D-1," },
                { "(s flip n e add)           ", "Move,man,X,C-1,C-2;Owner,man,O,D-1," },

                { "(e e flip e add)           ", "Move,man,X,C-1,C-4;Owner,man,O,C-3," },
                { "(s flip e add)             ", "Move,man,X,C-1,D-2;Owner,man,O,D-1," },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("movadd", new StringReader(tp));

                var result = game.LegalMoveParts
                             .Select(m => Util.Join(",", m.Kind, m.Piece, m.Player, m.Position, m.Final ?? "")).Join(";");
                Assert.AreEqual(matrix[i, 1], result, matrix[i, 0]);
            }
        }
Exemplo n.º 18
0
        public void BoardGridPositions()
        {
            Logger.Open(1);
            var input = new StringReader(
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @"(board (boardgrid45)) )"
                );
            var game = PolyGame.CreateInner("bgp", input);

            for (int i = 0; i < game.Positions.Count; ++i)
            {
                Assert.AreEqual(String.Format("{0}-{1}", "ABCD"[i / 5], "12345"[i % 5]), game.Positions[i].Name, "name");
                Assert.AreEqual(i / 5, game.Positions[i].Coords[0], "coord");
                Assert.AreEqual(i % 5, game.Positions[i].Coords[1], "coord");
            }
        }
Exemplo n.º 19
0
        public void MovesPlayed()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid45))" +
                @" (board-setup (X (man off 2 C-1)) (O (man off 2 B-1)))" +
                @" (piece (name man) (drops ((verify empty?) add)))" +
                @")";

            var matrix = new string[, ] {
                { "", "X;" },
                { "M", "O;X" },
                { "MM", "X;X,O" },
                { "MMM", "O;X,O,X" },
                { "MMMM", "X;X,O,X,O" },
                { "MMMMU", "O;X,O,X" },
                { "MMMMUU", "X;X,O" },
                { "MMMMUUU", "O;X" },
                { "MMMMUUUU", "X;" },

                { "MMS", "X;" },
                { "MMSU", "X;" },
                { "MMUUU", "X;" },
                { "MUUSRM", "O;X" },
            };
            var action = new Dictionary <char, Action <PolyGame> > {
                { 'M', g => g.MakeMove(0) },
                { 'U', g => g.UndoMove() },
                { 'R', g => g.RedoMove() },
                { 'S', g => g.Restart() },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var game = PolyGame.CreateInner("played", new StringReader(testprog));
                foreach (var ch in matrix[i, 0])
                {
                    action[ch](game);
                }
                var result = game.TurnPlayer + ";" + game.MovesPlayed
                             .Select(m => m.Player).Join(",");
                Assert.AreEqual(matrix[i, 1], result, matrix[i, 0]);
            }
        }
Exemplo n.º 20
0
        public void DropsBasic()
        {
            Logger.Open(1);
            var input = new StringReader(
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid33))" +
                @" (piece (piecedrops1))" +
                @" (board-setup (X(man A-1 B-1 off 5 C-1)) )" +
                @")");
            var game = PolyGame.CreateInner("bs1", input);

            var expstring = "Drop,X,man,A-1;Drop,X,man,A-2;Drop,X,man,A-3;Drop,X,man,B-1;Drop,X,man,B-2;Drop,X,man,B-3";
            var actstring = game.LegalMoveParts
                            .Select(m => Util.Join(",", m.Kind, m.Player, m.Piece, m.Position)).Join(";");

            Assert.AreEqual(expstring, actstring);
        }
Exemplo n.º 21
0
        public void CondWinTtt()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @" (game (gamestub1)" +
                @" (option ""pass turn"" true)" +
                @" (board (boardgrid33))" +
                @" (board-setup (X(man A-1 B-1 off 5 C-1)) )" +
                @" (piece (piece1))" +
                @" (win-condition (relcondttt))" +
                @")";
            var game = PolyGame.CreateInner("bs1", new StringReader(testprog));

            //Assert.AreEqual("Win", game.GameResult.ToString());
            game.MakeMove(0);
            Assert.AreEqual("Win", game.GameResult.ToString());
        }
Exemplo n.º 22
0
        public void DropPosOrZone()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @"(board (boardgrid45))" +
                @"(piece (piece1))" +
                @"(piece (piece2))" +
                @"(board-setup (X (man C-1) (xx off 1)) (O (man A-3)) (N (chip D-1)) )" +
                @"(piece (name xx) (drops {0}))" +
                @")";

            var matrix = new string[, ] {
                { "(B-4 add)", "B-4" },
                { "(B-4 add e add)", "B-4,B-5" },
                { "(B-4 add B-5 add)", "B-4,B-5" },
                { "(B-4 add e e add)", "B-4" },
                { "(B-4 s add)", "C-4" },
                { "(B-4 C-4 add)", "C-4" },
                { "(B-4 add)(C-4 add)", "B-4,C-4" },
                { "(C-4 add)(B-4 add)", "B-4,C-4" },

                { "(B-2 add e e (opposite e) add)", "B-2,B-3" },
                { "(B-2 add e (opposite n) add)", "B-2,C-3" },

                { "(endz add)", "D-1,D-2,D-3,D-4,D-5" },
                { "(endz e add)", "D-2,D-3,D-4,D-5" },
                { "(endz add)(B-4 add)", "B-4,D-1,D-2,D-3,D-4,D-5" },
                { "(B-4 add)(endz add)", "B-4,D-1,D-2,D-3,D-4,D-5" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("dporz", new StringReader(tp));

                Assert.IsTrue(game.LegalMoveParts.All(m => m.Kind == MoveKinds.Drop));
                Assert.IsTrue(game.LegalMoveParts.All(m => m.Piece == "xx"));
                Assert.IsTrue(game.LegalMoveParts.All(m => m.Player == "X"));
                var movestring = game.LegalMoveParts.Select(m => m.Position).OrderBy(m => m).Join(",");
                Assert.AreEqual(matrix[i, 1], movestring, matrix[i, 0]);
            }
        }
Exemplo n.º 23
0
        public void DropApply()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid45))" +
                @" (board-setup (X (man off 1 C-1) (chip off 1)))" +
                @" (piece (name man) (drops {0}))" +
                @" (piece (name chip))" +
                @")";

            var matrix = new string[, ] {
                { "(add)                          ", "A-1,X,man;C-1,X,man" },
                { "((add chip))                   ", "A-1,X,chip;C-1,X,man" },
                { "((add man chip))               ", "A-1,X,man;C-1,X,man" },

                { "(s s (add chip))               ", "C-1,X,chip" },
                { "(C-1 capture e (add chip))     ", "C-2,X,chip" },

                { "(C-1 flip add)                 ", "C-1,O,man" },
                { "(C-1 flip e (add chip))        ", "C-1,O,man;C-2,X,chip" },

                { "(C-1 change-owner add)         ", "C-1,X,man" },
                { "(C-1 change-owner e (add chip))", "C-1,X,man;C-2,X,chip" },

                { "(C-1 (change-type chip) add)   ", "C-1,X,chip" },
                { "(C-1 (change-type chip) e add) ", "C-1,X,chip;C-2,X,man" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("moveapply", new StringReader(tp));
                if (game.LegalMoves.Count > 0)
                {
                    game.MakeMove(0);
                }
                var result = game.PlayedPieces
                             .Select(p => Util.Join(",", p.Position, p.Player, p.Piece))
                             .OrderBy(s => s).Join(";");
                Assert.AreEqual(matrix[i, 1], result, matrix[i, 0]);
            }
        }
Exemplo n.º 24
0
        public void MoveSetState()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid45))" +
                @" (board-setup (X (man C-1)) (O (man A-3)) (N (chip D-1)) )" +
                @" (piece (name man) (moves {0}))" +
                @" (piece (name chip))" +
                @")";

            var matrix = new string[, ] {
                { "(e add)                        ", "Move,man,X,C-1,C-2" },
                { "(e n e s w add)                ", "Move,man,X,C-1,C-2" },
                // mark back
                { "(e mark n n back add)          ", "Move,man,X,C-1,C-2" },
                { "(e mark n n (go mark) add)     ", "Move,man,X,C-1,C-2" },
                { "(e (mark n) e back s add)      ", "Move,man,X,C-1,C-2" },
                { "(e (mark n) e (go mark) s add) ", "Move,man,X,C-1,C-2" },
                { "(e (mark C-1) e back e add)    ", "Move,man,X,C-1,C-2" },
                { "(e (mark C-1) e (go mark) e add)", "Move,man,X,C-1,C-2" },
                // from
                { "(e e (go from) e add)          ", "Move,man,X,C-1,C-2" },
                { "(e from to s from w n from add)", "Move,man,X,C-1,C-2" },
                { "(n from to s add)              ", "" },
                // to
                { "(e to e e add)                 ", "Move,man,X,C-1,C-2" },
                { "((go to) e add)                ", "Move,man,X,C-1,C-2" }, // to not set defaults to current
                { "(e (go to) add)                ", "Move,man,X,C-1,C-2" }, // to not set defaults to current
                { "(e to n (go to) add)           ", "Move,man,X,C-1,C-2" },
                { "(e e to n (go to) w to add)    ", "Move,man,X,C-1,C-2" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("dporz", new StringReader(tp));

                var movestring = game.LegalMoveParts
                                 .Select(m => Util.Join(",", m.Kind, m.Piece, m.Player, m.Position, m.Final ?? "")).Join(";");
                Assert.AreEqual(matrix[i, 1], movestring, matrix[i, 0]);
            }
        }
Exemplo n.º 25
0
        public void CondRelConfig()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (option ""pass turn"" true)" +
                @" (board (boardgrid33))" +
                @" (board-setup (X (man {0})))" +
                @" (piece (piece1))" +
                @" (win-condition (relcondttt))" +
                @")";
            var matrix = new string[, ] {
                { "           ", "-,None" },
                { "A-1        ", "-,None" },
                { "A-1 B-1    ", "-,None" },
                { "A-1 B-1 C-1", "X,Win" },
                { "A-2 B-2 C-2", "X,Win" },
                { "A-3 B-3 C-3", "X,Win" },
                { "A-1 B-2 C-1", "-,None" },
                { "A-1 A-2 A-3", "X,Win" },
                { "B-1 B-2 B-3", "X,Win" },
                { "C-1 C-2 C-3", "X,Win" },
                { "C-1 C-2 C-1", "-,None" },
                { "A-1 B-2 C-3", "X,Win" },
                { "A-3 B-2 C-1", "X,Win" },
                { "    B-2 C-1", "-,None" },
                { "        C-1", "-,None" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("bs1", new StringReader(tp));
                game.MakeMove(0);
                var expecteds = matrix[i, 1].SplitXY();
                Assert.AreEqual(expecteds[0], game.ResultPlayer.ToString(), matrix[i, 0]);
                Assert.AreEqual(expecteds[1], game.GameResult.ToString(), matrix[i, 0]);
                //var expected = game.LastPlayer + "," + game.GameResult;
                //Assert.AreEqual(matrix[i, 1], expected, matrix[i, 0]);
                //Assert.AreEqual(matrix[i, 1], game.GameResult, matrix[i, 0]);
            }
        }
Exemplo n.º 26
0
        public void BoardGrid45()
        {
            Logger.Open(1);
            var input = new StringReader(
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @"(board (boardgrid45)) )");
            var game = PolyGame.CreateInner("bt2", input);

            Assert.AreEqual(1, game.Menu.Count());
            Assert.AreEqual("stub1", game.Title);
            Assert.AreEqual("board45a.png", game.BoardImages[0]);
            Assert.AreEqual("board45b.png", game.BoardImages[1]);
            Assert.AreEqual("board45c.png", game.BoardImages[2]);

            var posnames = "ABCD".SelectMany(c => "12345".Select(r => String.Format("{0}-{1}", c, r))).ToArray();

            CollectionAssert.AreEqual(posnames, game.Positions.Select(p => p.Name).ToArray());
        }
Exemplo n.º 27
0
        public void MoveAttrib()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid45))" +
                @" (board-setup (X (man C-1)) (O (man C-3)) )" +
                @" (piece (name man) {0})" +
                @" (piece (name chip))" +
                @")";

            var matrix = new string[, ] {
                { "(attribute H1 true)  (moves (add))", "" },
                { "(attribute H1 true)  (moves (e add))", "Move,man,X,C-1,C-2," },
                { "(attribute H1 true)  (moves ((set-attribute H1 false) add))", "Attrib,man,X,C-1,null,H1 false" },

                { "(attribute H1 false) (moves ((verify H1) e add))", "" },
                { "(attribute H1 false) (moves ((verify (or H1 (empty? e))) e add))", "Move,man,X,C-1,C-2," },
                { "(attribute H1 true)  (moves ((verify H1) e add))", "Move,man,X,C-1,C-2," },
                { "(attribute H1 true)  (moves ((verify (and H1 empty?)) e add))", "" },

                { "(attribute H1 false) (moves ((if H1 e add)))", "" },
                { "(attribute H1 true)  (moves ((if H1 e add)))", "Move,man,X,C-1,C-2," },

                { "(attribute H1 false) (moves (e (if (H1 w) add)))", "" },
                { "(attribute H1 true)  (moves (e (if (H1 w) add)))", "Move,man,X,C-1,C-2," },
                { "(attribute H1 false) (moves (e (if (H1 C-1) add)))", "" },
                { "(attribute H1 true)  (moves (e (if (H1 C-1) add)))", "Move,man,X,C-1,C-2," },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("movadd", new StringReader(tp));

                var result = game.LegalMoveParts
                             .Select(m => Util.Join(",", m.Kind, m.Piece, m.Player, m.Position, m.Final,
                                                    m.Attribute == null ? "" : m.Attribute + " " + m.Value.ToString().ToLower())).Join(";");
                Assert.AreEqual(matrix[i, 1], result, matrix[i, 0]);
            }
        }
Exemplo n.º 28
0
        public void Choose2()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @" (board (boardgrid33))" +
                @" (draw-condition (X O) stalemated)" +
                @" (win-condition (relcondttt))" +
                @" (board-setup (X (man off 1 B-1)) (O (man off 1 C-1 C-2)))" +
                @" (piece (name man) (drops ((verify empty?) add)))" +
                @")";

            var matrix = new string[, ] {
                { "I;", "X,man,A-1;" },
                { "T;", "X,man,C-3;" },
                //{ "S;",         "X,man,C-3;" },
                //{ "1;",         "X,man,A-1;" },
                //{ "2;",         "X,man,C-3;" },
                //{ "F;",         "X,man,C-3;" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var game   = PolyGame.CreateInner("choice2", new StringReader(testprog));
                var result = "";
                foreach (var ch in matrix[i, 0])
                {
                    if (ch == ';')
                    {
                        result += Util.Join(",", game.ChosenMove.Player, game.ChosenMove.Piece1, game.ChosenMove.Position1) + ";";
                    }
                    else
                    {
                        actionlookup[ch](game);
                    }
                }
                //Assert.IsTrue(game.ChoicesIter().First().IsDone, matrix[i, 0]);
                Assert.AreEqual(matrix[i, 1], result, matrix[i, 0]);
            }
        }
Exemplo n.º 29
0
        public void CondPlayer()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (title ""cpl"") (players X O N) (turn-order (X N) (O N))" +
                @" (board (boardgrid33))" +
                @" (piece (name man) (drops ((verify empty?) add)))" +
                @" (board-setup (N (man off 2 A-1 A-2 A-3)) )" +
                @"({0})" +
                @")";
            var matrix = new string[, ] {
                // X plays as N at B-1, and then gets the result
                { "win-condition  (N) (absolute-config man (A-2))", "X,Win" },
                { "loss-condition (N) (absolute-config man (A-2))", "X,Loss" },
                { "draw-condition (N) (absolute-config man (A-2))", "-,Draw" },

                // X plays as N at B-1, and then gets the result
                { "win-condition  (N) (absolute-config man (B-1))", "X,Win" },
                { "loss-condition (N) (absolute-config man (B-1))", "X,Loss" },
                { "draw-condition (N) (absolute-config man (B-1))", "-,Draw" },

                // X plays as N at B-1, then O plays as N at B-2 and gets the result
                { "win-condition  (N) (absolute-config man (B-2))", "-,None;O,Win" },
                { "loss-condition (N) (absolute-config man (B-2))", "-,None;O,Loss" },
                { "draw-condition (N) (absolute-config man (B-2))", "-,None;-,Draw" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("cwld", new StringReader(tp));
                for (int j = 0; game.GameResult == ResultKinds.None; j++)
                {
                    game.MakeMove(0);
                    var expecteds = matrix[i, 1].SplitXY(j);
                    Assert.AreEqual(expecteds[0], game.ResultPlayer.ToString(), matrix[i, 0]);
                    Assert.AreEqual(expecteds[1], game.GameResult.ToString(), matrix[i, 0]);
                }
            }
        }
Exemplo n.º 30
0
        public void MoveTurnOrder()
        {
            Logger.Open(1);
            var testprog =
                @"(include ""testincl.poly"")" +
                @"(game (title ""moveto"")" +
                @" (players X O N)" +
                @" (turn-order (X N) (O N))" +
                @" (board (boardgrid33))" +
                @" (board-setup (X (man C-1)) (O (man C-3)) (N (man off 1)))" +
                @" (piece (name man) {0})" +
                @")";

            var matrix = new string[, ] {
                { "(drops ((verify empty?) add))", "A-1,A-2,A-3,B-1,B-2,B-3,C-2" },
            };

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                var tp   = String.Format(testprog, matrix[i, 0]);
                var game = PolyGame.CreateInner("movto", new StringReader(tp));

                Assert.IsTrue(game.LegalMoveParts.All(m => m.Kind == MoveKinds.Drop));
                Assert.IsTrue(game.LegalMoveParts.All(m => m.Piece == "man"));
                Assert.IsTrue(game.LegalMoveParts.All(m => m.Player == "N"));

                Assert.IsTrue(game.LegalMoves.All(m => m.Piece1 == "man"));
                Assert.IsTrue(game.LegalMoves.All(m => m.Piece2 == ""));
                Assert.IsTrue(game.LegalMoves.All(m => m.Position2 == ""));
                Assert.IsTrue(game.LegalMoves.All(m => m.Player == "N"));

                var positions = matrix[i, 1].Split(',');
                for (int j = 0; j < positions.Length; j++)
                {
                    Assert.AreEqual(positions[j], game.LegalMoveParts[j].Position);
                    Assert.AreEqual(j, game.LegalMoves[j].Index);
                    Assert.AreEqual(positions[j], game.LegalMoves[j].Position1);
                }
                Assert.IsTrue(game.LegalMoves.All(m => positions[m.Index] == m.Position1));
            }
        }