Exemple #1
0
    def test_resign_game(self):
        """ Tests resigning the game as the active player. """
        g = GessGame()

        g.resign_game()

        self.assertEqual('WHITE_WON', g.game_state)
Exemple #2
0
    def test_switch_turn1(self):
        """ Test switching the turn to the white player. """
        g = GessGame()

        g.switch_turn()

        self.assertEqual(g._players[1], g.get_active_player())
Exemple #3
0
    def test_switch_turn2(self):
        """ Test switching the turn back to the black player. """
        g = GessGame()

        g.switch_turn()
        g.switch_turn()

        self.assertEqual(g._players[0], g.get_active_player())
Exemple #4
0
    def test_check_win_condition1(self):
        """ Tests that a win condition is properly updated for white. """
        g = GessGame()
        g._players[1].set_rings([])

        g.check_win_condition()

        self.assertEqual('BLACK_WON', g.game_state)
Exemple #5
0
    def test_check_win_condition2(self):
        """ Tests that a win condition is properly updated for black. """
        g = GessGame()
        g._players[0].set_rings([])

        g.check_win_condition()

        self.assertEqual('WHITE_WON', g.game_state)
Exemple #6
0
    def test_update_rings3(self):
        """ Test removing a ring for white. """
        g = GessGame()

        target = {
            (18, 8): "",
            (18, 9): "w",
            (18, 10): "",
            (17, 8): "w",
            (17, 9): "w",
            (17, 10): "",
            (16, 8): "",
            (16, 9): "w",
            (16, 10): ""
        }

        g._board.place_piece(target)
        g.update_rings()

        self.assertListEqual([], g._players[1].get_rings())
Exemple #7
0
    def test_update_rings1(self):
        """ Test adding a new ring for white. """
        g = GessGame()

        target = {
            (18, 3): "",
            (18, 4): "w",
            (18, 5): "w",
            (17, 3): "w",
            (17, 4): "w",
            (17, 5): "w",
            (16, 3): "",
            (16, 4): "w",
            (16, 5): "w"
        }

        g._board.place_piece(target)
        g.update_rings()

        self.assertListEqual([(17, 6), (17, 11)], g._players[1].get_rings())
Exemple #8
0
    def test_update_rings2(self):
        """ Test adding a new ring for black. """
        g = GessGame()

        target = {
            (3, 3): "",
            (3, 4): "b",
            (3, 5): "b",
            (2, 3): "b",
            (2, 4): "b",
            (2, 5): "b",
            (1, 3): "",
            (1, 4): "b",
            (1, 5): "b"
        }

        g._board.place_piece(target)
        g.update_rings()

        self.assertListEqual([(2, 6), (2, 11)], g._players[0].get_rings())
Exemple #9
0
    def test_update_rings4(self):
        """ Test removing a ring for black. """
        g = GessGame()

        target = {
            (3, 8): "",
            (3, 9): "b",
            (3, 10): "",
            (2, 8): "b",
            (2, 9): "b",
            (2, 10): "",
            (1, 8): "",
            (1, 9): "b",
            (1, 10): ""
        }

        g._board.place_piece(target)
        error = False
        try:
            g.update_rings()
        except IllegalMove:
            error = True

        self.assertTrue(error)
Exemple #10
0
    def test_make_move9(self):
        """ Tests making a black move to the E. """
        g = GessGame()

        self.assertTrue(g.make_move('k7', 'l7'))
Exemple #11
0
    def test_make_move4(self):
        """ Tests completing a successful move. """
        g = GessGame()

        self.assertFalse(g.make_move('c7', 'c8'))
Exemple #12
0
    def test_make_move3(self):
        """ Tests destroying the last ring as the active player. """
        g = GessGame()

        self.assertFalse(g.make_move('j3', 'j5'))
Exemple #13
0
    def test_make_move2(self):
        """ Tests handling an illegal move. """
        g = GessGame()

        self.assertFalse(g.make_move('c6', 'd7'))
Exemple #14
0
    def test_check_win_condition4(self):
        """ Tests a natural win for the white player. """
        g = GessGame()

        g.make_move('f6', 'f9')  # black move
        g.make_move('l15', 'l12')  # white move
        g.make_move('f9', 'f12')  # black move
        g.make_move('l12', 'l9')  # white move
        g.make_move('f12', 'f13')  # black move
        g.make_move('l9', 'l8')  # white move
        g.make_move('f15', 'f14')  # black move
        g.make_move('l8', 'l5')  # white move

        self.assertEqual('WHITE_WON', g.game_state)
Exemple #15
0
    def test_check_win_condition3(self):
        """ Tests a natural win for the black player. """
        g = GessGame()

        g.make_move('l6', 'l9')  # black move
        g.make_move('c15', 'c12')  # white move
        g.make_move('l9', 'l12')  # black move
        g.make_move('c12', 'c9')  # white move
        g.make_move('l12', 'l13')  # black move
        g.make_move('c9', 'c8')  # white move
        g.make_move('l13', 'l16')  # black move

        self.assertEqual('BLACK_WON', g.game_state)
Exemple #16
0
    def test_make_move1(self):
        """ Tests trying to make a move after the game is finished. """
        g = GessGame()

        g.make_move('f6', 'f9')  # black move
        g.make_move('l15', 'l12')  # white move
        g.make_move('f9', 'f12')  # black move
        g.make_move('l12', 'l9')  # white move
        g.make_move('f12', 'f13')  # black move
        g.make_move('l9', 'l8')  # white move
        g.make_move('f15', 'f14')  # black move
        g.make_move('l8', 'l5')  # white move

        response = g.make_move('f14', 'f13')

        self.assertFalse(response)
Exemple #17
0
    def test_get_active_player(self):
        """ Tests returning the active player. """
        g = GessGame()

        self.assertEqual('b', g.get_active_player().get_stone())
Exemple #18
0
    def test_get_game_state(self):
        """ Tests returning the game state. """
        g = GessGame()

        self.assertEqual('UNFINISHED', g.game_state)
Exemple #19
0
    def test_make_move20(self):
        """ Tests making a white move to the SE. """
        g = GessGame()

        g.make_move('k8', 'l7')
        self.assertTrue(g.make_move('b15', 'c14'))
Exemple #20
0
    def test_make_move10(self):
        """ Tests making a black move to the SW. """
        g = GessGame()

        self.assertTrue(g.make_move('m8', 'l7'))
Exemple #21
0
    def test_make_move16(self):
        """ Tests making a white move to the W. """
        g = GessGame()

        g.make_move('k8', 'l7')
        self.assertTrue(g.make_move('d14', 'c14'))