Ejemplo n.º 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)
Ejemplo n.º 2
0
def test_created_board():
    """ Check that the board is created and all the cells
        contains the null_cell of the board 
    """

    array = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0,
                                     0], [0, 0, 0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0]]
    board = Board()
    board.created_board()

    # compare the array with the new board created
    assert (array == board.board)