Beispiel #1
0
        public void CowsPlacedOnEmptySpacesOnly(int pos, int numLeft, Color c)
        {
            IBoard b = Substitute.For <IBoard>();

            b.Occupant(Arg.Any <int>()).Returns(new Cow(-1, c));
            ICowBox  box = new CowBox();
            IReferee r   = new Referee(b, box);
            IPlayer  p1  = new Player(Color.Red, box);

            p1.Place(pos, b, r, Phase.Placing);

            //Cow was placed at empty position
            if (c == Color.Black)
            {
                //p1 has ll cows left
                Assert.True(box.RemainingCows(p1.Color) == 11);
            }

            //Position was occupied => no cow was placed
            //p1 still has all his cows
            else
            {
                Assert.True(box.RemainingCows(p1.Color) == 12);
            }
        }
Beispiel #2
0
        public void MillIsInvalidIfCowsNotInConnectedLine()
        {
            //TODO: Check that the cows that will form a mill are in a line and connected in spaces

            for (int i = 0; i < 22; i++)
            {
                for (int j = i + 1; j < 23; j++)
                {
                    for (int k = j + 1; k < 24; k++)
                    {
                        IBoard   b   = new Board();
                        ICowBox  box = new CowBox();
                        IReferee r   = new Referee(b, box);

                        b.Place(new Cow(-1, Color.Red), i);
                        b.Place(new Cow(-1, Color.Red), j);
                        b.Place(new Cow(-1, Color.Red), k);

                        IMill[] AnyMills = Mills.Where(x => x.Positions[0] == i && x.Positions[1] == j && x.Positions[2] == k).ToArray();

                        if (AnyMills.Length == 0)
                        {
                            Assert.False(b.areNewMills(Color.Red));
                        }
                        else
                        {
                            Assert.True(b.areNewMills(Color.Red));
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public static void CanCowsFlyAtFlyPhase()
        {
            for (int i = 0; i < 22; i++)
            {
                for (int j = i + 1; j < 23; j++)
                {
                    for (int k = j + 1; k < 24; k++)
                    {
                        IBoard   b   = new Board();
                        ICowBox  box = new CowBox();
                        IReferee r   = new Referee(b, box);

                        b.Place(new Cow(-1, Color.Red), i);
                        b.Place(new Cow(-1, Color.Red), j);
                        b.Place(new Cow(-1, Color.Red), k);

                        int[] EmptyPositions = Positions.Where(x => x != i && x != j && x != k).ToArray();

                        for (int l = 0; l < EmptyPositions.Length; l++)
                        {
                            Assert.True(r.CanFlyTo(Color.Red, EmptyPositions[l], Phase.Moving));
                            Assert.True(r.CanFlyTo(Color.Red, EmptyPositions[l], Phase.Moving));
                            Assert.True(r.CanFlyTo(Color.Red, EmptyPositions[l], Phase.Moving));
                        }
                    }
                }
            }
        }
Beispiel #4
0
 public Referee(IBoard board, Symbol player)
 {
     this.board         = board;
     this.currentPlayer = player;
     mill       = false;
     cowBox     = new CowBox(board);
     legalMoves = new LegalMoves(board, cowBox);
 }
Beispiel #5
0
        public static IGameSession CreateGameSession()
        {
            ICowBox      box         = new CowBox();
            IBoard       board       = new Board();
            IPlayer      P1          = new Player(Color.Red, box);
            IPlayer      P2          = new Player(Color.Blue, box);
            IReferee     referee     = new Referee(board, box);
            IGameSession gameSession = new GameSession(board, P1, P2, box, referee);

            return(gameSession);
        }
Beispiel #6
0
 public World(IPlayer p1, IPlayer p2)
 {
     this.player1 = p1;
     this.player2 = p2;
     this.board   = new Board();
     p1.setBoard(board);
     p2.setBoard(board);
     cowBox = new CowBox(board);
     p1.setCowBox(cowBox);
     p2.setCowBox(cowBox);
     referee               = new Referee(board, p1.symbol);
     legalMoves            = new LegalMoves(board, cowBox);
     referee.currentPlayer = p1.symbol;
 }
Beispiel #7
0
        public static void MoveCreatesNoDuplicates(int pos, int[] moves)
        {
            foreach (int move in moves)
            {
                IBoard   b   = new Board();
                ICowBox  box = new CowBox();
                IReferee r   = new Referee(b, box);

                b.Place(new Cow(-1, Color.Red), pos);
                b.Move(pos, move);

                ICow oldPosition = b.Occupant(pos);
                Assert.That(oldPosition.Color == Color.Black);
                Assert.That(b.numCowsOnBoard() == 1);
            }
        }
Beispiel #8
0
        public void ThreePlayerCowsInAlineFormsAMill()
        {
            IBoard   board   = new Board();
            ICowBox  box     = new CowBox();
            IPlayer  p       = new Player(Color.Red, box);
            IReferee referee = new Referee(board, box);

            //Place 2 cows in a row, no mills form
            Assert.False(board.areNewMills(Color.Red));
            p.Place(0, board, referee, Phase.Placing);
            Assert.False(board.areNewMills(Color.Red));
            p.Place(1, board, referee, Phase.Placing);
            Assert.False(board.areNewMills(Color.Red));

            //Place 3rd cow in a row, mill forms
            p.Place(2, board, referee, Phase.Placing);
            Assert.True(board.areNewMills(Color.Red));
        }
Beispiel #9
0
        public void MillIsInvalidIfCowsAreDifferentIDs()
        {
            IBoard   board   = new Board();
            ICowBox  box     = new CowBox();
            IPlayer  p1      = new Player(Color.Red, box);
            IPlayer  p2      = new Player(Color.Blue, box);
            IReferee referee = new Referee(board, box);

            //Player 1 and player 2 place cows next to each other
            Assert.False(board.areNewMills(Color.Red));
            p1.Place(0, board, referee, Phase.Placing);
            Assert.False(board.areNewMills(Color.Red));
            p2.Place(1, board, referee, Phase.Placing);
            Assert.False(board.areNewMills(Color.Red));

            //3rd cow is placed next to the above cows, no mill forms for either place
            p1.Place(2, board, referee, Phase.Placing);
            Assert.False(board.areNewMills(Color.Red));
            Assert.False(board.areNewMills(Color.Blue));
        }
Beispiel #10
0
        public void Only12CowsPlacedForEachPlayer()
        {
            IBoard   b   = new Board();
            ICowBox  box = new CowBox();
            IReferee r   = new Referee(b, box);
            IPlayer  p   = new Player(Color.Red, box);

            //Place all of p's cows
            for (int i = 0; i < 12; i++)
            {
                p.Place(i, b, r, Phase.Placing);
            }
            //Board should have all 12 of p's cows
            Assert.True(b.numCowsOnBoard() == 12);

            //try to place another cow for p
            p.Place(13, b, r, Phase.Placing);

            //Verify that no new cow has been placed
            Assert.True(b.numCowsOnBoard() == 12);
        }
Beispiel #11
0
        public static void MillCowIsSafeIfNonMillCowsExist(IMill mill)
        {
            //TODO: You cannot kill a cow in a mill if there exists cows that are not in a mill
            int[] placements        = mill.Positions;
            int[] AllOtherPositions = Positions.Where(x => x != placements[0] && x != placements[1] && x != placements[2]).ToArray();

            foreach (int pos in AllOtherPositions)
            {
                IBoard   b   = new Board();
                ICowBox  box = new CowBox();
                IReferee r   = new Referee(b, box);

                b.Place(new Cow(-1, Color.Red), placements[0]);
                b.Place(new Cow(-1, Color.Red), placements[1]);
                b.Place(new Cow(-1, Color.Red), placements[2]);

                b.Place(new Cow(-1, Color.Red), pos);

                foreach (int des in placements)
                {
                    Assert.False(r.CanKill(Color.Blue, des));
                }
            }
        }