Пример #1
0
    def change_settings(self, event):
        """Change settings."""
        # Change procedure.
        if event.GetId() == self._id_color_black:
            game = othello.OthelloGame(player_color='black')
            game.load_strategy(Strategy)
            self._frame.othello = game
        if event.GetId() == self._id_color_white:
            game = othello.OthelloGame(player_color='white')
            game.load_strategy(Strategy)
            self._frame.othello = game
        if event.GetId() == self._id_color_random:
            game = othello.OthelloGame(player_color='random')
            game.load_strategy(Strategy)
            self._frame.othello = game

        # Change_strategy.
        if event.GetId() == self._id_random:
            return self._frame.othello.change_strategy("random", False)
        if event.GetId() == self._id_maximize:
            return self._frame.othello.change_strategy("maximize", False)
        if event.GetId() == self._id_minimize:
            return self._frame.othello.change_strategy("minimize", False)
        if event.GetId() == self._id_openness:
            return self._frame.othello.change_strategy("openness_theory",
                                                       False)
        if event.GetId() == self._id_evenness:
            return self._frame.othello.change_strategy("evenness_theory",
                                                       False)
        if event.GetId() == self._id_minmax:
            return self._frame.othello.change_strategy("min-max", False)
Пример #2
0
def new_game(first_player, black_weights, white_weights):
    game = othello.OthelloGame(ROWS,
                               COLUMNS,
                               othello.BLACK,
                               first_player=first_player,
                               black_weights=black_weights,
                               white_weights=white_weights)
    return game
Пример #3
0
 def new_game(self) -> None:
     ''' Creates a new game'''
     self.game = othello.OthelloGame(self.rows, self.columns,
                                     self.first_player)
     self.board.new_game_settings(self.game)
     self.board.redraw_board()
     self.black_score.update_score(self.game)
     self.white_score.update_score(self.game)
     self.player_turn.update_turn(self.game.turn)
Пример #4
0
 def _new_game(self) -> None:
     ''' Creates a new game with current _game_state settings '''
     self._game_state = othello.OthelloGame(self._rows, self._columns,
                                            self._first_player,
                                            self._top_left_player,
                                            self._victory_type)
     self._board.new_game_settings(self._game_state)
     self._board.redraw_board()
     self._black_score.update_score(self._game_state)
     self._white_score.update_score(self._game_state)
     self._player_turn.update_turn(self._game_state.get_turn())
Пример #5
0
 def test_eat_all(self):
     test = othello.OthelloGame(8)
     for vertical_index, row in enumerate(test.board):
         for horizontal_index, chess in enumerate(row):
             if vertical_index == 0 or horizontal_index == 0 or vertical_index == test.size_of_board-1 or horizontal_index == test.size_of_board-1:
                 chess.chess_type = othello.Chess.BLACK
             elif vertical_index == 5 and horizontal_index == 5:
                 chess.chess_type = othello.Chess.EMPTY
             else:
                 chess.chess_type = othello.Chess.WHITE
     print(test)
     self.assertTrue(test.move(5, 5))
     print(test)
     for row in test.board:
         for chess in row:
             self.assertEqual(chess.get_type(), othello.Chess.BLACK)
Пример #6
0
    def __init__(self):
        # Game settings
        self.rows = ROWS
        self.columns = COLUMNS
        self.first_player = FIRST_PLAYER

        self.game = othello.OthelloGame(self.rows, self.columns,
                                        self.first_player)

        # Board game setting
        self.window = tkinter.Tk()
        self.window.title('OTHELLO')
        self.window.configure(background=BACKGROUND_COLOR)
        self.board = models.GameBoard(self.game, BOARD_WIDTH, BOARD_HEIGHT,
                                      self.window)
        self.black_score = models.Score(othello.BLACK, self.game, self.window)
        self.white_score = models.Score(othello.WHITE, self.game, self.window)
        self.player_turn = models.Turn(self.game, self.window)

        # Bind my game board with these two events.
        self.board.board.bind('<Configure>', self.on_board_resized)
        self.board.board.bind('<Button-1>', self.on_board_clicked)

        # restart button
        self.restart_icon = Image.open("assets/restart.jpg")
        self.restart_icon = ImageOps.fit(self.restart_icon, (40, 40))
        self.restart_icon = ImageTk.PhotoImage(self.restart_icon)
        self.restart_button = tkinter.Label(master=self.window,
                                            image=self.restart_icon,
                                            cursor="hand2",
                                            bg=BACKGROUND_COLOR)
        self.restart_button.bind('<Button-1>', self.restart_button_clicked)

        # exit button
        self.exit_icon = Image.open("assets/home.jpg")
        self.exit_icon = ImageOps.fit(self.exit_icon, (40, 40))
        self.exit_icon = ImageTk.PhotoImage(self.exit_icon)
        self.exit_button = tkinter.Label(master=self.window,
                                         image=self.exit_icon,
                                         cursor="hand2",
                                         bg=BACKGROUND_COLOR)
        self.exit_button.bind('<Button-1>', self.exit_button_clicked)

        # Layout all the widgets here using grid layout
        self.board.board.grid(row=0,
                              column=0,
                              columnspan=2,
                              sticky=tkinter.N + tkinter.E + tkinter.S +
                              tkinter.W)
        self.black_score.score_label.grid(row=1,
                                          column=0,
                                          pady=20,
                                          sticky=tkinter.N)
        self.white_score.score_label.grid(row=1,
                                          column=1,
                                          pady=20,
                                          sticky=tkinter.N)
        self.player_turn.turn_label.grid(row=2,
                                         column=0,
                                         columnspan=2,
                                         padx=10,
                                         pady=20)
        self.restart_button.grid(row=3,
                                 column=0,
                                 pady=10,
                                 sticky=tkinter.E,
                                 padx=10)
        self.exit_button.grid(row=3,
                              column=1,
                              pady=10,
                              sticky=tkinter.W,
                              padx=10)

        # Configure the root window's row/column weight (from the grid layout)
        self.window.rowconfigure(0, weight=1)
        self.window.rowconfigure(1, weight=1)
        self.window.rowconfigure(2, weight=1)
        self.window.rowconfigure(3, weight=1)
        self.window.columnconfigure(0, weight=1)
        self.window.columnconfigure(1, weight=1)
Пример #7
0
    def __init__(self, agent_b, agent_w):
        # AI agents
        self._agent_b = agent_b
        self._agent_w = agent_w
        # Initial Game Settings
        self._rows = DEFAULT_ROWS
        self._columns = DEFAULT_COLUMNS
        self._first_player = DEFAULT_FIRST_PLAYER
        self._top_left_player = DEFAULT_TOP_LEFT_PLAYER
        self._victory_type = DEFAULT_VICTORY_TYPE

        # Create my othello gamestate here (drawn from the original othello game code)
        self._game_state = othello.OthelloGame(self._rows, self._columns,
                                               self._first_player,
                                               self._top_left_player,
                                               self._victory_type)

        # Initialize all my widgets and window here
        self._root_window = tkinter.Tk()
        self._root_window.configure(background=BACKGROUND_COLOR)
        self._board = othello_models.GameBoard(self._game_state, GAME_WIDTH,
                                               GAME_HEIGHT, self._root_window)
        self._black_score = othello_models.Score(othello.BLACK,
                                                 self._game_state,
                                                 self._root_window)
        self._white_score = othello_models.Score(othello.WHITE,
                                                 self._game_state,
                                                 self._root_window)
        self._player_turn = othello_models.Turn(self._game_state,
                                                self._root_window)

        # Bind my game board with these two events.
        self._board.get_board().bind('<Configure>', self._on_board_resized)
        # self._board.get_board().bind('<Button-1>', self._on_board_clicked)

        # Create our menu that can be accessed at the top of the GUI
        self._menu_bar = tkinter.Menu(self._root_window)
        #self._game_menu = tkinter.Menu(self._menu_bar, tearoff = 0)
        #self._game_menu.add_command(label = 'New Game', command = self._new_game)
        #self._game_menu.add_command(label = 'Game Settings', command = self._configure_game_settings)
        #self._game_menu.add_separator()
        #self._game_menu.add_command(label = 'Exit', command = self._root_window.destroy)
        #self._menu_bar.add_cascade(label = 'Game', menu = self._game_menu)

        # Layout all the widgets here using grid layout
        self._root_window.config(menu=self._menu_bar)
        self._black_score.get_score_label().grid(row=0,
                                                 column=0,
                                                 sticky=tkinter.S)
        self._white_score.get_score_label().grid(row=0,
                                                 column=1,
                                                 sticky=tkinter.S)
        self._board.get_board().grid(row=1,
                                     column=0,
                                     columnspan=2,
                                     padx=50,
                                     pady=10,
                                     sticky=tkinter.N + tkinter.E + tkinter.S +
                                     tkinter.W)
        self._player_turn.get_turn_label().grid(row=2,
                                                column=0,
                                                columnspan=2,
                                                padx=10,
                                                pady=10)

        # Configure the root window's row/column weight (from the grid layout)
        self._root_window.rowconfigure(0, weight=1)
        self._root_window.rowconfigure(1, weight=1)
        self._root_window.rowconfigure(2, weight=1)
        self._root_window.columnconfigure(0, weight=1)
        self._root_window.columnconfigure(1, weight=1)
Пример #8
0
 def initialize_game(self):
     """Initialize board."""
     game = othello.OthelloGame()
     game.load_strategy(Strategy)
     self._frame.othello = game
     return
Пример #9
0
""""""

import wx

import gui
import othello
from strategy import Strategy

if __name__ == "__main__":
    game = othello.OthelloGame()
    game.load_strategy(Strategy)

    application = wx.App()
    frame = gui.MyFrame(title="Othello Game", othello=game)

    frame.Center()
    frame.Show()
    application.MainLoop()
    wx.Exit()