Example #1
0
 public void ItemTest2()
 {
     Board target = new Board();
     int y = -1;
     int x = 9;
     target[y, x] = new Draught(9, -1, DraughtType.None, Players.PlayerOne);
 }
Example #2
0
        public static DraughtsGame Deserialize(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
                throw new ArgumentException();

            Draught[,] draughts = new Draught[8, 8];
            Board board;
            DraughtsGame game;

            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader br = new BinaryReader(fs))
                {
                    Players currentTurn = (Players)br.ReadByte();
                    int leftOne = br.ReadByte();
                    int leftTwo = br.ReadByte();

                    for (int i = 0; i < leftOne + leftTwo; i++)
                    {
                        int drY = br.ReadByte();
                        int drX = br.ReadByte();
                        DraughtType type = (DraughtType)br.ReadByte();
                        Players player = (Players)br.ReadByte();

                        draughts[drY, drX] = new Draught(new BoardPoint(drY, drX), type, player);
                    }

                    board = new Board(draughts, leftOne, leftTwo);
                    game = new DraughtsGame() { CurrentTurn = currentTurn, GameBoard = board };
                }
            }

            return game;
        }
Example #3
0
 public void ItemTest1()
 {
     Board target = new Board();
     int y = -1;
     int x = 9;
     Draught expected = target[y, x];
     target[y, x] = expected;
 }
Example #4
0
        public void EndCellIsNotNullTurnTest()
        {
            Draught[,] draughts = new Draught[8, 8];
            draughts[0, 1] = new Draught(1, 0, DraughtType.None, Players.PlayerOne);
            draughts[1, 2] = new Draught(2, 1, DraughtType.None, Players.PlayerOne);
            draughts[7, 1] = new Draught(0, 7, DraughtType.None, Players.PlayerTwo);
            Board board = new Board(draughts, 2, 1);
            DraughtsGame game = new DraughtsGame() { GameBoard = board, CurrentTurn = Players.PlayerOne };

            game.Turn(1, 0, 2, 1);
        }
Example #5
0
        public void ItemTest()
        {
            Board target = new Board();
            int y = 5;
            int x = 4;
            Draught expected = target[y, x];
            Assert.AreEqual<Draught>(expected, target[y, x]);

            target[y, x] = expected;
            Assert.AreEqual<Draught>(target[y, x], expected);
        }
Example #6
0
        public void DraughtToQueen()
        {
            Draught[,] draughts = new Draught[8, 8];
            draughts[1, 2] = new Draught(2, 1, DraughtType.None, Players.PlayerTwo);
            Draught nonQueen = new Draught(3, 2, DraughtType.None, Players.PlayerOne);
            draughts[2, 3] = nonQueen;

            Board board = new Board(draughts, 1, 1);
            DraughtsGame game = new DraughtsGame() { GameBoard = board };
            game.Turn(3, 2, 1, 0);

            Assert.AreEqual(DraughtType.None, nonQueen.Type);
        }
Example #7
0
 public void RemoveTest()
 {
     Board target = new Board();
     int x = 3;
     int y = 2;
     target.Remove(x, y);
     Assert.IsNull(target[y, x]);
 }
Example #8
0
 public void MoveTest9()
 {
     Board board = new Board();
     Draught dr = null;
     board.Move(dr, new BoardPoint(3, 2));
 }
Example #9
0
        public void MoveTest8()
        {
            Board board = new Board();
            Draught dr = board[2, 1];
            BoardPoint point = new BoardPoint(3, 2);
            board.Move(dr, point);

            Assert.AreEqual(board[point], dr);
        }
Example #10
0
        public void QueenTurnTest()
        {
            Draught[,] draughts = new Draught[8, 8];
            Draught dr = new Draught(1, 0, DraughtType.Queen, Players.PlayerOne);
            draughts[0, 1] = dr;
            Board board = new Board(draughts, 1, 1);
            DraughtsGame game = new DraughtsGame { GameBoard = board };

            // вниз-вправо
            game.Turn(1, 0, 4, 3);
            Assert.AreEqual<Draught>(dr, game.GameBoard[3, 4]);
            game.CurrentTurn = Players.PlayerOne;

            // вверх-вправо
            game.Turn(4, 3, 6, 1);
            Assert.AreEqual<Draught>(dr, game.GameBoard[1, 6]);
            game.CurrentTurn = Players.PlayerOne;

            // вниз-влево
            game.Turn(6, 1, 2, 5);
            Assert.AreEqual<Draught>(dr, game.GameBoard[5, 2]);
            game.CurrentTurn = Players.PlayerOne;

            // вверх-влево
            game.Turn(2, 5, 0, 3);
            Assert.AreEqual<Draught>(dr, game.GameBoard[3, 0]);
            game.CurrentTurn = Players.PlayerOne;
        }
Example #11
0
        public void RemoveTest5()
        {
            Board target = new Board();
            BoardPoint point = new BoardPoint(2, 3);
            target.Remove(point);

            Assert.IsNull(target[point]);
        }
Example #12
0
 public void RemoveTest3()
 {
     Board target = new Board();
     int x = 3;
     int y = 2;
     target[y, x] = null;
     target.Remove(x, y);
 }
Example #13
0
        public void MoveTest3()
        {
            Board target = new Board();
            int oldX = 3;
            int oldY = 2;
            Draught draught = target[oldY, oldX];

            int newX = 4;
            int newY = 4;
            target.Move(oldX, oldY, newX, newY);
        }
Example #14
0
        public void MoveTest1()
        {
            Board target = new Board();
            int oldX = 3;
            int oldY = 2;
            Draught draught = target[oldY, oldX];

            int newX = 4;
            int newY = 3;
            target.Move(draught, newX, newY);
            Assert.AreEqual<Draught>(draught, target[newY, newX]);
        }
Example #15
0
 public void KillOwnDraught()
 {
     Draught[,] draughts = new Draught[8, 8];
     draughts[0, 1] = new Draught(1, 0, DraughtType.Queen, Players.PlayerOne);
     draughts[1, 2] = new Draught(2, 1, DraughtType.None, Players.PlayerOne);
     draughts[7, 0] = new Draught(0, 7, DraughtType.None, Players.PlayerOne);
     Board board = new Board(draughts, 2, 1);
     DraughtsGame game = new DraughtsGame() { GameBoard = board, CurrentTurn = Players.PlayerOne };
     game.Turn(1, 0, 3, 2);
 }
Example #16
0
        public void QueenWrongTurnTest()
        {
            Draught[,] draughts = new Draught[8, 8];
            Draught dr = new Draught(1, 0, DraughtType.Queen, Players.PlayerOne); ;
            draughts[0, 1] = dr;
            Board board = new Board(draughts, 1, 0);
            DraughtsGame game = new DraughtsGame { GameBoard = board };

            game.Turn(1, 0, 6, 7);
        }
Example #17
0
 public void RemoveTest1()
 {
     Board target = new Board();
     int x = 3;
     int y = 2;
     Draught draught = target[y, x];
     target.Remove(draught);
     Assert.IsNull(target[y, x]);
 }
Example #18
0
 public void RemoveTest2()
 {
     Board target = new Board();
     int x = 3;
     int y = 3;
     target.Remove(x, y);
 }
Example #19
0
        public void MoveTest4()
        {
            Board target = new Board();
            int oldX = 3;
            int oldY = 2;
            target[oldY, oldX] = null;

            int newX = 4;
            int newY = 3;
            target.Move(oldX, oldY, newX, newY);
        }
Example #20
0
 public void RemoveTest4()
 {
     Board target = new Board();
     int x = 3;
     int y = 2;
     target.Remove(x, y);
     Assert.AreEqual<int>(11, target.LeftDraughtPlayerTwo);
 }
Example #21
0
        public void MoveTest5()
        {
            Board target = new Board();
            int oldX = 2;
            int oldY = 1;

            int newX = 3;
            int newY = 2;
            target.Move(oldX, oldY, newX, newY);
        }
Example #22
0
        public void ItemTest3()
        {
            Board target = new Board();
            BoardPoint point = new BoardPoint(5, 4);
            Draught expected = target[point];
            Assert.AreEqual<Draught>(expected, target[point]);

            target[point] = expected;
            Assert.AreEqual<Draught>(target[point], expected);
        }
Example #23
0
        public void QueenKillTest()
        {
            Draught[,] draughts = new Draught[8, 8];
            Draught quuen = new Draught(1, 0, DraughtType.Queen, Players.PlayerOne); ;
            draughts[0, 1] = quuen;
            Draught dr = new Draught(3, 2, DraughtType.None, Players.PlayerTwo);
            draughts[2, 3] = dr;

            Board board = new Board(draughts, 1, 0);
            DraughtsGame game = new DraughtsGame { GameBoard = board };

            game.Turn(1, 0, 7, 6);
            Assert.AreEqual<Draught>(quuen, game.GameBoard[6, 7]);
        }
Example #24
0
 public void MoveTest6()
 {
     Board target = new Board();
     int newX = 3;
     int newY = 2;
     target.Move(null, newX, newY);
 }
Example #25
0
        public void QueenTurnBackTest()
        {
            Draught[,] draughts = new Draught[8, 8];
            Draught dr = new Draught(4, 3, DraughtType.Queen, Players.PlayerOne); ;
            draughts[3, 4] = dr;
            Board board = new Board(draughts, 1, 0);
            DraughtsGame game = new DraughtsGame { GameBoard = board };

            game.Turn(4, 3, 1, 0);
            Assert.AreEqual<Draught>(dr, game.GameBoard[0, 1]);
        }
Example #26
0
 public DraughtsGame()
 {
     board = new Board();
     canKill = false;
     StartNew();
 }
Example #27
0
        public void MoveTest7()
        {
            Board target = new Board();
            BoardPoint oldPoint = new BoardPoint(2, 3);
            Draught draught = target[oldPoint];

            BoardPoint newPoint = new BoardPoint(3, 4);
            target.Move(draught, newPoint);
            Assert.AreEqual<Draught>(draught, target[newPoint]);
        }