示例#1
0
class GameGenetics:
    def __init__(self, player_1, player_2):
        self.board = Board()
        self.player_1 = player_1
        self.player_2 = player_2
        self.turn_player_1 = False

    def play_game(self):
        self.board.created_board()
        while (not self.is_winner()):
            if (self.board.is_full()):
                #print("Empate")
                return cf.TIE
            self.turn_player_1 = not self.turn_player_1
            if (self.turn_player_1):
                col = self.player_1.next_action(deepcopy(self.board))
                self.board.set_value_cell(col, 1)
            else:
                col = self.player_2.next_action(deepcopy(self.board))
                self.board.set_value_cell(col, 2)
        return self.who_is_winner()

    def who_is_winner(self):
        if (self.turn_player_1):
            return cf.WINNER_1
        else:
            return cf.WINNER_2

    def is_winner(self):
        last_mov = self.board.get_last_mov()
        if (self.turn_player_1):
            return self.board.winner(last_mov[0], last_mov[1], 1)
        else:
            return self.board.winner(last_mov[0], last_mov[1], 2)
示例#2
0
def test_is_full_false():
    """ Check that the board is not really full 
    """

    array = [[1, 1, 2, 0, 0, 1, 1], [2, 1, 1, 1, 2, 1,
                                     2], [1, 1, 2, 1, 1, 1, 2],
             [2, 2, 1, 2, 2, 2, 1], [1, 1, 2, 2, 1, 1, 2],
             [2, 1, 2, 1, 1, 2, 2]]
    board = Board()
    board.board = array

    assert (board.is_full() == False)
示例#3
0
def test_is_full_true():
    """ Check that the board is really full 
    """

    array = [[1, 1, 2, 2, 2, 1, 1], [2, 1, 1, 1, 2, 1,
                                     2], [1, 1, 2, 1, 1, 1, 2],
             [2, 2, 1, 2, 2, 2, 1], [1, 1, 2, 2, 1, 1, 2],
             [2, 1, 2, 1, 1, 2, 2]]
    board = Board()
    board.board = array

    assert (board.is_full() == True)