public void CannotCompactDifferentSizes() { var board = new Board(4); // {0, 0, 0, 2}, // {0, 0, 0, 1}, // {1 ,0, 0, 2}, // {0, 0, 1, 0} board.Set(c00, new Piece(PieceType.Get(0), 1)); board.Set(c10, new Piece(PieceType.Get(0), 1)); board.Set(c20, new Piece(PieceType.Get(1), 1)); board.Set(c30, new Piece(PieceType.Get(0), 1)); board.Set(c01, new Piece(PieceType.Get(1), 1)); board.Set(c11, new Piece(PieceType.Get(0), 1)); board.Set(c21, new Piece(PieceType.Get(3), 1)); board.Set(c31, new Piece(PieceType.Get(3), 1)); board.Set(c02, new Piece(PieceType.Get(0), 2)); board.Set(c22, new Piece(PieceType.Get(0), 1)); board.Set(c32, new Piece(PieceType.Get(1), 1)); board.Set(c23, new Piece(PieceType.Get(0), 1)); board.Set(c33, new Piece(PieceType.Get(2), 1)); var compactor = new BoardCompactor(board); Assert.IsFalse(compactor.CanCompact(c11)); Assert.IsFalse(compactor.CanCompact(c12)); }
public void TestPieceSerialization() { string tstr = @"{ ""index"": 0}"; var json = JSON.Parse(tstr); var t = PieceType.FromJSON(json); Assert.AreEqual(0, t.index); for (int i = 0; i < 100; i++) { var tt = PieceType.Get(i); var tjson = tt.ToJSON(); var tout = PieceType.FromJSON(tjson); Assert.AreEqual(i, tt.index, "initial type has correct index"); Assert.AreEqual(i, tout.index, "deserialized type has correct index"); Assert.AreEqual(tt.index, tout.index, "both have correct index"); Assert.IsTrue(tt.Matches(PieceType.FromJSON(tjson)), "serialize -> deserialize results in same type"); } for (int i = 0; i < 10; i++) { for (int size = 1; size <= 16; size *= 2) { var p = new Piece(PieceType.Get(i), size); Assert.IsTrue(p.Matches(Piece.FromJSON(p.ToJSON())), "piece matches its serialized -> deserialized"); } } }
public void DifferentSizesDontMatch() { Piece p1 = new Piece(PieceType.Get(0), 1); Piece p2 = new Piece(PieceType.Get(0), 2); Assert.IsFalse(p1.Matches(p2)); Assert.IsFalse(p2.Matches(p1)); }
public void NotEqualPiecesCanMatch() { Piece p1 = new Piece(PieceType.Get(0), 1); Piece p2 = new Piece(PieceType.Get(0), 1); Assert.AreNotEqual(p1, p2); Assert.IsTrue(p1.Matches(p2)); Assert.IsTrue(p2.Matches(p1)); }
public Board GenerateRandom(int size, int numTypes, bool compact = true) { return(GenerateRandom(size, new PieceType[] { PieceType.Get(0), PieceType.Get(1), PieceType.Get(2) }, compact)); }
public void AllDontMatchDifferentType() { var pieces = new Piece[] { new Piece(PieceType.Get(1), 2), new Piece(PieceType.Get(0), 2), new Piece(PieceType.Get(0), 2) }; Assert.IsFalse(Piece.AllMatch(pieces)); }
public void BoardScaling() { var board = builder.FromTypeGrid("01 23"); var cloned = builder.CloneScaled(board, 2); Assert.IsTrue(new Piece(PieceType.Get(0), 2).Matches(cloned.Get(c02))); Assert.IsTrue(new Piece(PieceType.Get(1), 2).Matches(cloned.Get(c22))); Assert.IsTrue(new Piece(PieceType.Get(2), 2).Matches(cloned.Get(c00))); Assert.IsTrue(new Piece(PieceType.Get(3), 2).Matches(cloned.Get(c20))); }
public void SetOnEmptyCoords() { var board = new Board(2); foreach (var coord in board.AllCoords) { board.Set(coord, new Piece(PieceType.Get(0), 1)); } Assert.Pass("No exceptions thrown"); }
public void SimpleCompaction2x2() { var board = builder.FromTypeGrid("00 01"); var compactor = new BoardCompactor(board); Assert.IsFalse(compactor.CanCompact()); board.Remove(c10); board.Set(c10, new Piece(PieceType.Get(0), 1)); Assert.IsTrue(compactor.CanCompact()); compactor.Compact(); Assert.IsTrue(piece_t0_s2.Matches(board.Get(c00)), "board:\n" + board); }
public void FromTypeGridCompactsBoard() { var grid = new int[, ] { { 0, 0, 1, 2 }, { 0, 0, 2, 1 }, { 2, 2, 1, 2 }, { 1, 2, 2, 2 } }; var board = builder.FromTypeGrid(grid); var expectedPiece = new Piece(PieceType.Get(0), 2); var piece_c03 = board.Get(c03); Assert.IsTrue(expectedPiece.Matches(piece_c03)); }
public void RotateRight() { // 12 c01 c11 // 34 c00 c10 var board = builder.FromTypeGrid("1234"); board.RotateRight(); // 31 c01 c11 // 42 c00 c10 Assert.AreEqual(PieceType.Get(3), board.Get(c01).type); Assert.AreEqual(PieceType.Get(1), board.Get(c11).type); Assert.AreEqual(PieceType.Get(4), board.Get(c00).type); Assert.AreEqual(PieceType.Get(2), board.Get(c10).type); }
void Start() { var types = new PieceType[] { PieceType.Get(0), PieceType.Get(1), PieceType.Get(2) }; var game = new Game( new BoardGenerator().GenerateRandom(16, types), GameRules.ClassicRules, PieceType.GetRange(0, 3)); bc.SetGame(game, texture); }
public void AllMatch() { var pieces = new Piece[] { new Piece(PieceType.Get(0), 1), new Piece(PieceType.Get(0), 1), new Piece(PieceType.Get(0), 1) }; Assert.IsTrue(Piece.AllMatch(pieces)); pieces = new Piece[] { new Piece(PieceType.Get(0), 2), new Piece(PieceType.Get(0), 2), new Piece(PieceType.Get(0), 2) }; Assert.IsTrue(Piece.AllMatch(pieces)); }
public void TestBoardLoadingWithPointers() { var jsonStr = @" { ""size"" : 4, ""pointers"" : [""0/2->0:2"", ""0/2->2:2"", ""0/2->2:0"", ""0/1->0:0"", ""0/1->1:0"", ""0/1->0:1"", ""1/1->1:1""] }" ; var board = Board.FromJSON(JSON.Parse(jsonStr)); Assert.NotNull(board, "board was parsed and is not null"); Assert.AreEqual(4, board.Size, "board size is correct"); var piece = board.Get(new Coord(0, 0)); Assert.NotNull(piece, "there is a piece @ 0,0"); Assert.AreEqual(1, piece.size, "piece @ 0,0 size 1"); piece = board.Get(new Coord(0, 2)); Assert.NotNull(piece, "there is a piece @ 0,2"); Assert.AreEqual(2, piece.size, "piece @ 0,0 size 2"); Assert.IsTrue(piece.type.Matches(PieceType.Get(0)), "piece @ 0,0 type 0"); }
public void CanCompactAligned2x2Recursive() { var board = builder.FromTypeGrid(new int[, ] { { 1, 0, 1, 0, 1, 0, 1, 0 }, { 1, 0, 1, 0, 1, 0, 1, 0 }, { 2, 2, 2, 2, 1, 0, 1, 0 }, { 2, 2, 2, 2, 1, 0, 1, 0 }, { 2, 2, 1, 2, 1, 0, 1, 0 }, { 2, 2, 1, 2, 1, 0, 1, 0 }, { 1, 0, 1, 0, 1, 0, 1, 0 }, { 1, 0, 1, 0, 1, 0, 1, 0 } }); board.Remove(c22); board.Remove(c23); board.Set(c22, new Piece(PieceType.Get(2), 1)); board.Set(c23, new Piece(PieceType.Get(2), 1)); var compactor = new BoardCompactor(board); Assert.IsTrue(compactor.CanCompact(), "board:\n" + board); compactor.Compact(); Assert.AreEqual(4, board.Get(c02).size); }
public void PieceCoordsContainPiece() { var board = new Board(4); foreach (var size in new int[] { 1, 2, 4 }) { foreach (var coord in AllCordsStepping(board.Size, size)) { var piece = new Piece(PieceType.Get(1), size); board.Set(coord, piece); var pieceCoords = board.PieceCoords(piece); foreach (var c in pieceCoords) { Assert.AreEqual(piece, board.Get(c)); Assert.GreaterOrEqual(c.col, coord.col); Assert.GreaterOrEqual(c.row, coord.row); Assert.Less(c.col, coord.col + size); Assert.Less(c.row, coord.row + size); } board.Remove(coord); } } }
public void PieceMatchesSelf() { Piece p1 = new Piece(PieceType.Get(0), 1); Assert.IsTrue(p1.Matches(p1)); }