Example #1
0
    def test_castlecompletion(self):
        t1 = Tile6()
        t2 = Tile16()
        t2.turn_clockwise()
        t3 = Tile16()
        t3.turn_counterclockwise()

        attach_left_right(t2, t1)
        attach_left_right(t1, t3)

        self.assertFalse((None, None)
                         not in t1.dfs_start(t1.sides[0]))  # not completed

        t4 = Tile16()
        t4.turn_clockwise()
        t4.turn_clockwise()
        attach_up_down(t4, t1)

        self.assertTrue((None, None)
                        not in t1.dfs_start(t1.sides[0]))  # completed
Example #2
0
    def test_2(self):
        t1 = Tile25()  # first tile

        t2 = Tile9()
        self.assertEqual(t1.fit_up(t2), False)
        t2.turn_counterclockwise()
        self.assertEqual(t1.fit_up(t2), True)  # fits after rotating
        attach_up_down(t2, t1)
        # can place a pawn in the castle and on the meadow
        self.assertEqual(t2.offer_to_place_a_pawn(), [(10, Terrains.CASTLE),
                                                      (1, Terrains.MEADOW)])
        t2.place_a_pawn(10, 1)  # player 1 place a pawn in the castle
        self.assertEqual(t2.after_move(), {})  # no points given

        # one turn:
        # -if no tiles remain run function after_game() for each tile, merge their dictionaries and send to all clients
        # -if there is a tile remaining take it from a deck
        # -check if it can be placed anywhere on the board in any of its 4 possible rotations
        # -if no, cast it aside and draw another tile
        # -otherwise, send possible coordinates to the client
        # -upon response from the client attach the tile to all adjecent ones
        # -run offer_to_place_a_pawn() in the recently placed tile
        # -for the convenience of frontend representation position of these pawns should be translated with the
        #   other_reciprocal(num) function from Tile.py  ex. 4 = (1, 6) and then sent, upon response
        #   if client did place a pawn its position should be translated back and then function
        #   place_a_pawn(position, player) should be executed with the translated position as a 'position' parameter
        # -execute function after_move() and sent the resulting dictionary to the client ({player: [points, No. pawns]})

        t3 = Tile16()
        t3.turn_clockwise()
        self.assertTrue(t2.fit_left(t3))  # fits
        attach_left_right(t3, t2)  # what a bad move from player 2!
        self.assertEqual(t3.offer_to_place_a_pawn(), [(7, Terrains.MEADOW)])
        # decides not to place a pawn
        self.assertEqual(t3.after_move(), {
            1: [8, 1]
        })  # he gave player 1 8 points!(6 from catle tiles 2 from a shield)
    def test_counting_points(self):
        # 18 8 13 18 19 14
        # 13 8 17 20 22 13
        # 15 2 23 15 22 25
        # 9  4 18 25 17 16

        t1 = Tile18()  # 1 turn
        t1.turn_clockwise()
        t1.turn_clockwise()

        t2 = Tile8()  # 2 turn
        t2.turn_clockwise()
        t2.turn_clockwise()
        attach_left_right(t1, t2)

        t3 = Tile13()  # 3 turn
        attach_left_right(t2, t3)

        t4 = Tile18()  # 4 turn
        t4.turn_counterclockwise()
        attach_left_right(t3, t4)

        t5 = Tile19()  # 5 turn
        t5.turn_clockwise()
        attach_left_right(t4, t5)

        t6 = Tile14()  # 6 turn
        t6.turn_counterclockwise()
        attach_left_right(t5, t6)

        t7 = Tile13()  # 7 turn
        t7.turn_clockwise()
        attach_up_down(t1, t7)

        t8 = Tile8()  # 8 turn
        t8.turn_clockwise()
        attach_left_right(t7, t8)
        attach_up_down(t2, t8)

        t9 = Tile17()  # 9 turn
        t9.turn_counterclockwise()
        attach_left_right(t8, t9)
        attach_up_down(t3, t9)

        t10 = Tile20()  # 10 turn
        t10.turn_clockwise()
        t10.turn_clockwise()
        attach_left_right(t9, t10)
        attach_up_down(t4, t10)

        t11 = Tile22()  # 11 turn
        t11.turn_clockwise()
        attach_left_right(t10, t11)
        attach_up_down(t5, t11)

        t12 = Tile13()  # 12 turn
        t12.turn_clockwise()
        attach_left_right(t11, t12)
        attach_up_down(t6, t12)

        t13 = Tile15()  # 13 turn
        attach_up_down(t7, t13)

        t14 = Tile2()  # 14 turn
        t14.turn_counterclockwise()
        attach_left_right(t13, t14)
        attach_up_down(t8, t14)

        t15 = Tile23()  # 15 turn
        t15.turn_clockwise()
        attach_left_right(t14, t15)
        attach_up_down(t9, t15)

        t16 = Tile15()  # 16 turn
        attach_left_right(t15, t16)
        attach_up_down(t10, t16)

        t17 = Tile22()  # 17 turn
        t17.turn_counterclockwise()
        attach_left_right(t16, t17)
        attach_up_down(t11, t17)

        t18 = Tile25()  # 18 turn
        attach_left_right(t17, t18)
        attach_up_down(t12, t18)

        t19 = Tile9()  # 19 turn
        t19.turn_clockwise()
        attach_up_down(t13, t19)

        t20 = Tile4()  # 20 turn
        t20.turn_clockwise()
        t20.turn_clockwise()
        attach_left_right(t19, t20)
        attach_up_down(t14, t20)

        t21 = Tile18()  # 21 turn
        t21.turn_counterclockwise()
        attach_left_right(t20, t21)
        attach_up_down(t15, t21)

        t22 = Tile25()  # 22 turn
        attach_left_right(t21, t22)
        attach_up_down(t16, t22)

        t23 = Tile17()  # 23 turn
        t23.turn_clockwise()
        attach_left_right(t22, t23)
        attach_up_down(t17, t23)

        t24 = Tile16()  # 24 turn
        t24.turn_counterclockwise()
        attach_left_right(t23, t24)
        attach_up_down(t18, t24)

        self.assertEqual(t1.offer_to_place_a_pawn(),
                         [(11, Terrains.ROAD), (7, Terrains.CASTLE), (10, Terrains.MEADOW), (12, Terrains.MEADOW)])
        t1.place_a_pawn(t1.offer_to_place_a_pawn()[2][0], 1)  # 1 player put pawn on meadow

        self.assertEqual(t2.offer_to_place_a_pawn(), [(7, Terrains.CASTLE)])

        self.assertEqual(t3.offer_to_place_a_pawn(), [(4, Terrains.CASTLE), (1, Terrains.MEADOW), (7, Terrains.MEADOW)])

        self.assertEqual(t4.offer_to_place_a_pawn(),
                         [(2, Terrains.ROAD), (10, Terrains.CASTLE), (1, Terrains.MEADOW), (3, Terrains.MEADOW)])

        self.assertEqual(t5.offer_to_place_a_pawn(),
                         [(4, Terrains.CASTLE), (7, Terrains.MEADOW), (9, Terrains.MEADOW), (12, Terrains.MEADOW),
                          (2, Terrains.ROAD), (8, Terrains.ROAD), (11, Terrains.ROAD)])

        self.assertEqual(t6.offer_to_place_a_pawn(),
                         [(10, Terrains.CASTLE), (7, Terrains.CASTLE), (1, Terrains.MEADOW)])

        self.assertEqual(t7.offer_to_place_a_pawn(),
                         [(7, Terrains.CASTLE), (4, Terrains.MEADOW), (10, Terrains.MEADOW)])

        self.assertEqual(t8.offer_to_place_a_pawn(), [(4, Terrains.CASTLE), (7, Terrains.MEADOW)])
        t8.place_a_pawn(t8.offer_to_place_a_pawn()[1][0], 2)  # 2 player put pawn on meadow

        self.assertEqual(t9.offer_to_place_a_pawn(),
                         [(10, Terrains.CASTLE), (5, Terrains.ROAD), (6, Terrains.MEADOW)])

        self.assertEqual(t10.offer_to_place_a_pawn(),
                         [(11, Terrains.ROAD), (7, Terrains.CASTLE), (10, Terrains.MEADOW)])

        self.assertEqual(t11.offer_to_place_a_pawn(),
                         [(4, Terrains.MEADOW), (11, Terrains.ROAD)])
        t11.place_a_pawn(t11.offer_to_place_a_pawn()[0][0], 4)  # 4 player put pawn on meadow

        self.assertEqual(t12.offer_to_place_a_pawn(), [(7, Terrains.CASTLE), (4, Terrains.MEADOW)])

        self.assertEqual(t13.offer_to_place_a_pawn(),
                         [(1, Terrains.CASTLE), (7, Terrains.CASTLE)])

        self.assertEqual(t14.offer_to_place_a_pawn(), [(5, Terrains.ROAD), (0, Terrains.MONASTERY)])

        self.assertEqual(t15.offer_to_place_a_pawn(), [(2, Terrains.ROAD), (8, Terrains.ROAD), (11, Terrains.ROAD)])

        self.assertEqual(t16.offer_to_place_a_pawn(), [(1, Terrains.CASTLE), (7, Terrains.CASTLE)])
        t16.place_a_pawn(t16.offer_to_place_a_pawn()[0][0], 3)  # 3 player put pawn on castle

        self.assertEqual(t17.offer_to_place_a_pawn(), [(5, Terrains.ROAD)])

        self.assertEqual(t18.offer_to_place_a_pawn(), [(1, Terrains.CASTLE), (5, Terrains.ROAD)])
        t18.place_a_pawn(t18.offer_to_place_a_pawn()[1][0], 4)  # 4 player put pawn on meadow

        self.assertEqual(t19.offer_to_place_a_pawn(), [(4, Terrains.CASTLE), (7, Terrains.MEADOW)])

        self.assertEqual(t20.offer_to_place_a_pawn(), [(7, Terrains.CASTLE)])

        self.assertEqual(t21.offer_to_place_a_pawn(), [(10, Terrains.CASTLE)])

        self.assertEqual(t22.offer_to_place_a_pawn(), [(1, Terrains.CASTLE)])

        self.assertEqual(t23.offer_to_place_a_pawn(), [(4, Terrains.CASTLE)])

        self.assertEqual(t24.offer_to_place_a_pawn(), [(10, Terrains.CASTLE)])
        t24.place_a_pawn(t24.offer_to_place_a_pawn()[0][0], 1)  # 1 player put pawn on castle
Example #4
0
    def test_whole_board(self):
        # t1  t2  t3  t4  t5  t6
        # t7  t8  t9  t10 t11 t12
        # t13 t14 t15 t16 t17 t18
        # t19 t20 t21 t22 t23 t24

        t1 = Tile18()
        t2 = Tile8()
        t3 = Tile13()
        t4 = Tile18()
        t5 = Tile19()
        t6 = Tile14()
        t7 = Tile13()
        t8 = Tile8()
        t9 = Tile17()
        t10 = Tile20()
        t11 = Tile22()
        t12 = Tile13()
        t13 = Tile15()
        t14 = Tile2()
        t15 = Tile23()
        t16 = Tile15()
        t17 = Tile22()
        t18 = Tile25()
        t19 = Tile9()
        t20 = Tile4()
        t21 = Tile18()
        t22 = Tile25()
        t23 = Tile17()
        t24 = Tile16()

        t1.turn_clockwise()
        t1.turn_clockwise()
        t2.turn_clockwise()
        t2.turn_clockwise()
        t4.turn_counterclockwise()
        t5.turn_clockwise()
        t6.turn_counterclockwise()
        t7.turn_clockwise()
        t8.turn_clockwise()
        t9.turn_counterclockwise()
        t10.turn_clockwise()
        t10.turn_clockwise()
        t11.turn_clockwise()
        t12.turn_clockwise()
        t14.turn_counterclockwise()
        t15.turn_clockwise()
        t17.turn_counterclockwise()
        t19.turn_clockwise()
        t20.turn_clockwise()
        t20.turn_clockwise()
        t21.turn_counterclockwise()
        t23.turn_clockwise()
        t24.turn_counterclockwise()

        attach_left_right(t1, t2)
        attach_left_right(t2, t3)
        attach_left_right(t3, t4)
        attach_left_right(t4, t5)
        attach_left_right(t5, t6)
        attach_left_right(t7, t8)
        attach_left_right(t8, t9)
        attach_left_right(t9, t10)
        attach_left_right(t10, t11)

        attach_left_right(t11, t12)

        attach_left_right(t13, t14)
        attach_left_right(t14, t15)
        attach_left_right(t15, t16)
        attach_left_right(t16, t17)
        attach_left_right(t17, t18)
        attach_left_right(t19, t20)
        attach_left_right(t20, t21)
        attach_left_right(t21, t22)
        attach_left_right(t22, t23)
        attach_left_right(t23, t24)

        attach_up_down(t1, t7)
        attach_up_down(t7, t13)
        attach_up_down(t13, t19)
        attach_up_down(t2, t8)
        attach_up_down(t8, t14)
        attach_up_down(t14, t20)
        attach_up_down(t3, t9)
        attach_up_down(t9, t15)
        attach_up_down(t15, t21)
        attach_up_down(t4, t10)
        attach_up_down(t10, t16)
        attach_up_down(t16, t22)
        attach_up_down(t5, t11)
        attach_up_down(t11, t17)
        attach_up_down(t17, t23)
        attach_up_down(t6, t12)
        attach_up_down(t12, t18)
        attach_up_down(t18, t24)

        t1.sides[2][3] = 1
        t24.sides[1][3] = 1
        t8.sides[1][3] = 2
        t16.sides[2][3] = 3
        t11.sides[0][3] = 4
        t18.sides[3][3] = 4

        self.assertEqual(t2.check_for_points_after_game_castle(),
                         {})  # no one is there

        t20.sides[0][3] = 1
        self.assertEqual(t20.check_for_points_after_game_castle(),
                         {1: 5})  # player 1 is there

        self.assertEqual(t8.check_for_points_after_game_meadow(), {2: 9, 1: 9})
        self.assertEqual(t11.check_for_points_after_game_meadow(), {
            4: 12,
            3: 12
        })
        self.assertEqual(t1.check_for_points_after_game_meadow(), {1: 6})

        t24.sides[0][3] = 1
        self.assertEqual(t24.check_for_points_after_game_castle(), {1: 2})

        t14.center[3] = 2
        self.assertEqual(t14.check_for_points_after_game_monastery(), {2: 9})
Example #5
0
    def test_1(self):
        # IDs
        #    t1 t2 t3
        # t4 t5 t6 t7

        # Tiles
        #    T14 T16 T8
        # T9 T20 T2  T16

        t1 = Tile14()
        t2 = Tile16()
        t3 = Tile8()
        t4 = Tile11()
        t5 = Tile20()
        t6 = Tile2()
        t7 = Tile16()

        # rotate
        t1.turn_clockwise()
        t1.turn_clockwise()
        t2.turn_counterclockwise()
        t3.turn_clockwise()
        t3.turn_clockwise()
        t6.turn_clockwise()

        # connect
        attach_left_right(t1, t2)
        attach_left_right(t2, t3)
        attach_left_right(t4, t5)
        attach_left_right(t5, t6)
        attach_left_right(t6, t7)
        attach_up_down(t1, t5)
        attach_up_down(t2, t6)
        attach_up_down(t3, t7)

        # place pawns
        t1.sides[2][3] = 2
        t2.sides[1][3] = 2
        t3.sides[0][3] = 2
        t4.sides[2][3] = 2
        t5.sides[0][3] = 1
        t6.center[3] = 1
        t7.sides[1][3] = 1

        # first tile, player two gains 3 points for each castle adjecent to his meadow
        self.assertEqual(t1.after_game(), {2: 6})

        # second tile, player two gains 3 points for each castle adjecent to his meadow and player 1 gains nothing,
        # because player 2 outnumbers his pawns on this meadow
        self.assertEqual(t2.after_game(), {2: 6})

        # third tile, player two gains 1 point for each fragment of his unfinished castle
        self.assertEqual(t3.after_game(), {2: 2})

        # fourth tile, this meadow was already checked, so there is no pawn
        self.assertEqual(t4.after_game(), {})

        # fifth tile, player 1 gets 3 points for his unfinished road
        self.assertEqual(t5.after_game(), {1: 3})

        # sixth tile, player 1 gets 6 points for his unfinished monastery
        self.assertEqual(t6.after_game(), {1: 6})

        # seventh tile, this meadow was already checked, so there is no pawn
        self.assertEqual(t7.after_game(), {})
Example #6
0
    def test_counting_points(self):
        # t1  t2  t3  t4  t5  t6
        # t7  t8  t9  t10 t11 t12
        # t13 t14 t15 t16 t17 t18
        # t19 t20 t21 t22 t23 t24

        t1 = Tile18()  # 1 turn
        t1.turn_clockwise()
        t1.turn_clockwise()
        t1.place_a_pawn(10, 1)  # 1 player put pawn on meadow

        t2 = Tile8()  # 2 turn
        t2.turn_clockwise()
        t2.turn_clockwise()
        attach_left_right(t1, t2)

        t3 = Tile13()  # 3 turn
        attach_left_right(t2, t3)

        t4 = Tile18()  # 4 turn
        t4.turn_counterclockwise()
        attach_left_right(t3, t4)

        t5 = Tile19()  # 5 turn
        t5.turn_clockwise()
        attach_left_right(t4, t5)

        t6 = Tile14()  # 6 turn
        t6.turn_counterclockwise()
        attach_left_right(t5, t6)

        t7 = Tile13()  # 7 turn
        t7.turn_clockwise()
        attach_up_down(t1, t7)

        t8 = Tile8()  # 8 turn
        t8.turn_clockwise()
        attach_left_right(t7, t8)
        attach_up_down(t2, t8)
        t8.place_a_pawn(7, 2)  # 2 player put pawn on meadow

        t9 = Tile17()  # 9 turn
        t9.turn_counterclockwise()
        attach_left_right(t8, t9)
        attach_up_down(t3, t9)

        t10 = Tile20()  # 10 turn
        t10.turn_clockwise()
        t10.turn_clockwise()
        attach_left_right(t9, t10)
        attach_up_down(t4, t10)

        t11 = Tile22()  # 11 turn
        t11.turn_clockwise()
        attach_left_right(t10, t11)
        attach_up_down(t5, t11)
        t11.place_a_pawn(4, 4)  # 4 player put pawn on meadow

        t12 = Tile13()  # 12 turn
        t12.turn_clockwise()
        attach_left_right(t11, t12)
        attach_up_down(t6, t12)

        t13 = Tile15()  # 13 turn
        attach_up_down(t7, t13)

        t14 = Tile2()  # 14 turn
        t14.turn_counterclockwise()
        attach_left_right(t13, t14)
        attach_up_down(t8, t14)

        t15 = Tile23()  # 15 turn
        t15.turn_clockwise()
        attach_left_right(t14, t15)
        attach_up_down(t9, t15)

        t16 = Tile15()  # 16 turn
        attach_left_right(t15, t16)
        attach_up_down(t10, t16)
        t16.place_a_pawn(1, 3)  # 3 player put pawn on castle

        t17 = Tile22()  # 17 turn
        t17.turn_counterclockwise()
        attach_left_right(t16, t17)
        attach_up_down(t11, t17)

        t18 = Tile25()  # 18 turn
        attach_left_right(t17, t18)
        attach_up_down(t12, t18)
        t18.place_a_pawn(6, 4)  # 4 player put pawn on meadow

        t19 = Tile9()  # 19 turn
        t19.turn_clockwise()
        attach_up_down(t13, t19)

        t20 = Tile4()  # 20 turn
        t20.turn_clockwise()
        t20.turn_clockwise()
        attach_left_right(t19, t20)
        attach_up_down(t14, t20)

        t21 = Tile18()  # 21 turn
        t21.turn_counterclockwise()
        attach_left_right(t20, t21)
        attach_up_down(t15, t21)

        t22 = Tile25()  # 22 turn
        attach_left_right(t21, t22)
        attach_up_down(t16, t22)

        t23 = Tile17()  # 23 turn
        t23.turn_clockwise()
        attach_left_right(t22, t23)
        attach_up_down(t17, t23)
        t23.place_a_pawn(11, 1)  # 1 player put pawn on road

        t24 = Tile16()  # 24 turn
        t24.turn_counterclockwise()
        attach_left_right(t23, t24)
        attach_up_down(t18, t24)
        t24.place_a_pawn(10, 1)  # 1 player put pawn on castle

        self.assertEqual(t1.after_game(),
                         {1: 6})  # there is only 1 player on tile1
        self.assertEqual(t2.after_game(), {})
        self.assertEqual(t3.after_game(), {})
        self.assertEqual(t4.after_game(), {})
        self.assertEqual(t5.after_game(), {})
        self.assertEqual(t6.after_game(), {})
        self.assertEqual(t7.after_game(), {})
        self.assertEqual(t8.after_game(), {
            2: 9,
            4: 9
        })  # there are 2 pawns(from player 2 and 4)
        self.assertEqual(t9.after_game(), {})
        self.assertEqual(t10.after_game(), {})
        self.assertEqual(t11.after_game(),
                         {4: 12})  # player 4 is the only one on this meadow
        self.assertEqual(t12.after_game(), {})
        self.assertEqual(t13.after_game(), {})
        self.assertEqual(t14.after_game(), {})
        self.assertEqual(t15.after_game(), {})
        self.assertEqual(t16.after_game(), {3: 2})
        self.assertEqual(t17.after_game(), {})
        self.assertEqual(t18.after_game(), {})
        self.assertEqual(t19.after_game(), {})
        self.assertEqual(t20.after_game(), {})
        self.assertEqual(t21.after_game(), {})
        self.assertEqual(t22.after_game(), {})
        self.assertEqual(t23.after_game(),
                         {1: 6})  # there is a pawn from player 1 on the castle
        self.assertEqual(t24.after_game(), {1: 2})