class Game:
    def __init__(self, file_name):
        self.__board = Board(3, 3)
        self.__file_name = file_name

    def move(self, args) -> Cell:
        pass

    def move_computer(self, col, args):
        '''
        This function makes a move for the human part

        '''
        for column in range(9):
            if col == column:
                if self.__board.is_valid() == True:
                    self.__board.set_cell(col - 1, args)
                    return self.__board.print_board()

    def move_human(self, col, args):
        '''

        This function makes a move for the human part
        '''
        for column in range(9):
            if col == column:
                if self.__board.is_valid() == True:
                    self.__board.set_cell(col - 1, args)
                    return self.__board.print_board()
Exemple #2
0
class Console:
    def __init__(self, repo):
        self.__repo = repo
        self.__board = Board(3, 3)

    def run_menu(self):
        while True:
            try:
                print("1. Start playing.")
                cmd = int(input("Enter a command: "))
                if cmd == 1:
                    self.__start()
                else:
                    break

            except ValueError as ve:
                print(ve)

    def __start(self):
        n = 0
        turn = 0
        k = 0
        print(Board(3, 3).print_board())
        while k < 9:
            if turn % 2 == 0:
                col = int(input("Enter a line: "))
                if 0 < col < 9:
                    pass
                else:
                    raise ValueError("Invalid number.")
                # self.__repo.move_human(col-1, 'X')
                k += 1
                print(self.__board.set_cell(col - 1, 'X'))

                turn += 1

            if turn % 2 == 1 and n < 4:
                self.__repo.move_computer(n, 'O')
                n += 1
                k += 1
                print(self.__board.set_cell(n, 'O'))
                turn += 1
Exemple #3
0
    def __start(self):
        n = 0
        turn = 0
        k = 0
        print(Board(3, 3).print_board())
        while k < 9:
            if turn % 2 == 0:
                col = int(input("Enter a line: "))
                if 0 < col < 9:
                    pass
                else:
                    raise ValueError("Invalid number.")
                # self.__repo.move_human(col-1, 'X')
                k += 1
                print(self.__board.set_cell(col - 1, 'X'))

                turn += 1

            if turn % 2 == 1 and n < 4:
                self.__repo.move_computer(n, 'O')
                n += 1
                k += 1
                print(self.__board.set_cell(n, 'O'))
                turn += 1
 def test_get_columns(self):
     board = Board(3, 3)
     self.assertequal(board.get_columns(),3)
 def Setup(self):
     board = Board(3,3)
 def test_set_columns_values(self):
     board = Board(3, 3)
     board.set_cell(1,3)
 def test_get_lines(self):
     board = Board(3, 3)
     self.assertequal(board.get_lines(),3)
 def __init__(self, file_name):
     self.__board = Board(3, 3)
     self.__file_name = file_name
Exemple #9
0
 def __init__(self, repo):
     self.__repo = repo
     self.__board = Board(3, 3)