コード例 #1
0
def lancejeu():
    """Routine de lancement du jeu"""
    print('OTHELLO avec une IA')

    #
    #########joueur VS joueur #######################
    jblanc = joueur.Joueur('Blanc', 'o')
    jnoir = joueur.Joueur('Noir', 'x')
    jeu = po.Othello(jblanc, jnoir)
    #    ####### joueur VS ia_faible #####################
    #    jblanc = joueur.Joueur('Blanc', 'o')
    #    ia_faib = iaf.IAFaible('iafaible','x')
    #    jeu = po.Othello(jblanc,ia_faib)
    #    ####### joueur VS ia_forte ######################
    #    jblanc = joueur.Joueur('Blanc', 'o')
    #    ia_fort = iaF.IAForte('iaforte','x')
    #    jeu = po.Othello(jblanc,ia_fort)
    #    ####### ia_faible VS ia_forte ###################
    #    ia_faib = iaf.IAFaible('iafaible','o')
    #    ia_fort = iaF.IAForte('iaforte','x')
    #    jeu = po.Othello(ia_faib,ia_fort)
    #    #################################################
    #
    jeu.info()
    jeu.jeu()
コード例 #2
0
ファイル: othello_model.py プロジェクト: jakeeqsb/Othello
 def init_othello(self, row, col, first_p, wincond, b_list, w_list):
     '''
     This initializes an othello object.
     '''
     board = othello.make_board(row, col, b_list, w_list)
     self.oth = othello.Othello(row, col, first_p, wincond, board)
     self.oth.is_there_winner()
     self.oth.corner_case()
コード例 #3
0
ファイル: driver.py プロジェクト: sriram13m/Othello
def main():

    root = othello.tk.Tk()
    computer1 = player.Player(3, -1)
    computer2 = player.Player(4, 1)
    game = othello.Othello(computer1, computer2, master=root)

    game.mainloop()
コード例 #4
0
 def __init__(self, master=None, couleur=oth.NOIR, table=None):
     tk.Frame.__init__(self, master)
     self.master = master
     self.jeu = oth.Othello(table)
     # self.joueur est la couleur du joueur physique,
     # self.jeu.joueur est le joueur dont c'est le tour
     self.joueur = couleur
     self.create_widgets()
コード例 #5
0
ファイル: main.py プロジェクト: qinemma/Othello
    def __init__(self):
        super().__init__()
        self.images = {}  # image resources
        self.keys_down = {}  # records of down-keys

        # create game object
        self.game = othello.Othello()

        self.debug = False  # True for debugging
コード例 #6
0
ファイル: game.py プロジェクト: SiyanH/othello-game
def main():
    # Initializes the game
    game = othello.Othello()
    game.draw_board()
    game.initialize_board()

    # Starts playing the game
    # The user makes a move by clicking one of the squares on the board
    # The computer makes a random legal move every time
    # Game is over when there are no more lagal moves or the board is full
    game.run()
コード例 #7
0
def _start_game() -> 'Othello':
    '''
    This function starts the interaction with the user by asking for the size of
    the gameboard they wish to play Othello on, the player with the
    first turn and how the game is won. This information is used to create
    an Othello object with those specifications.
    '''
    print('FULL')

    info_list = []

    while (len(info_list) == 0):
        try:
            row = int(input())
            if (row % 2 == 1 or row < 4 or row > 16):
                print('ERROR')
                continue
            info_list.append(row)

            column = int(input())
            if (column % 2 == 1 or column < 4 or column > 16):
                print('ERROR')
                info_list = []
                continue
            info_list.append(column)

            first_turn_player = input().upper()
            if not (first_turn_player == 'B' or first_turn_player == 'W'):
                print('ERROR')
                info_list = []
                continue
            info_list.append(first_turn_player)

            win_condition = input()
            if not (win_condition == '>' or win_condition == '<'):
                print('ERROR')
                info_list = []
                continue

            info_list.append(win_condition)

        except ValueError:
            print('ERROR')
            info_list = []
            continue

    return othello.Othello(info_list[0], info_list[1], info_list[2],
                           info_list[3])
コード例 #8
0
    def __init__(self : 'CounterPositions', rows : int, columns : int,
                 first_turn_player : str, win_condition : str) \
                 -> 'CounterPositions':
        '''
        The constructor for the CounterPositions class. It holds an Othello
        object to handle the game logic of Othello. The counter locations
        held what and where the counters were placed on the board. Spot
        coordinates hold the positions of each grid within the Othello board.
        Initial setup holds the information for the initial gameboard state.
        '''
        self.gameboard = othello.Othello(rows, columns, first_turn_player,
                                    win_condition)
        self.counter_locations = []
        self.spot_coordinates = []
        self.initial_setup = []
        
        for row_index in range(rows):
            
            self.initial_setup.append([])
            self.spot_coordinates.append([])
            
            for column_index in range(columns):
                new_spot = othello_point.from_frac(
                             (row_index + row_index + 1) / (2 * rows),
                             (column_index + column_index + 1) / (2 * columns))

                if (1/rows) <= (1/columns):
                    end_point = othello_point.from_frac(
                        row_index / rows,
                        (column_index + column_index + 1) / (2 * columns))

                else:
                    end_point = othello_point.from_frac(
                        (row_index + row_index + 1) / (2 * rows),
                        column_index / columns)
                
                new_radius = new_spot.distance_from_frac(end_point)

                new_counter = Counter(new_spot, new_radius,
                                      1 / (2 * rows), 1 / (2 * columns))
                
                self.spot_coordinates[row_index].append(new_counter)
                self.initial_setup[row_index].append('.')
コード例 #9
0
def _run_game():
    '''run the game, play the game, takes in 2 players, they alternate'''
    print("\nFULL")
    col = choose_num_col()
    row = choose_num_row()
    '''Asks user input for turn and winning criteria'''
    turn = input()
    winning_criteria = input()
    #board = get_board(col, row)
    board = [['.', '.', '.', '.'], ['.', 'B', 'B', '.'], ['.', 'B', 'B', '.'],
             ['.', '.', '.', '.']]
    '''creates an object of the class Othello'''
    ogame = othello.Othello(col, row, winning_criteria, turn, board)
    while True:
        '''principle while loop that runs through the steps of thello printing
        number of tiles, the board, current turn, and switching tiles'''
        try:
            if not ogame.no_more_empty_spaces():
                ogame.print_num_tiles()
                ogame.print_screen()
                ogame.print_player_turn()
                while not ogame.check_and_switch(get_coord()):
                    print("INVALID")
                print("VALID")
                ogame.change_player_turn()
            elif ogame.winner() == ogame.BLACK:
                ogame.print_num_tiles()
                ogame.print_screen()
                print("WINNER:", ogame_BLACK)
                break
            elif ogame.winner() == ogame.WHITE:
                ogame.print_num_tiles()
                ogame.print_screen()
                print("WINNER:", ogame.WHITE)
                break
            elif ogame.winner() == ogame.NONE:
                ogame.print_num_tiles()
                ogame.print_screen()
                print("WINNER: NONE")
                break
        except IndexError:
            pass
コード例 #10
0
        col_input = move[1]
        othello_game.get_list_moves(row_input, col_input)

        while (othello_game.check_valid() == False):
            print("INVALID")
            move = get_move(othello_game)
            row_input = move[0]
            col_input = move[1]
            othello_game.get_list_moves(row_input, col_input)

        print("VALID")

        othello_game.turn_disks(row_input, col_input)
        othello_game.change_turn()

    othello_game.count_disks()
    print("B: " + str(othello_game.bcount) + "  W: " +
          str(othello_game.wcount))
    othello_game.print_board()
    othello_game.print_winner()


if __name__ == "__main__":
    print("FULL")
    try:
        rows, columns, turn, mode, start_board = get_user_info()
        othello_game = othello.Othello(rows, columns, turn, mode, start_board)
        play_game(othello_game)
    except:
        pass
コード例 #11
0
'''
Created on May 17, 2017

@author: jonathanlin
'''
import othello

obj = othello.Othello(
    3, 5, "B", ">",
    [". . . . . .", "B W W W W .", ". . . . . .", ". . . . . ."])
try:
    coord = obj._check_left(1, 5)
    assert (coord == (1, 0))
    print("Left 1 Passed")
except:
    print("Left 1 Failed")

obj = othello.Othello(
    5, 3, "B", ">",
    [". . . .", "B W W .", ". . . .", ". . . .", ". . . .", ". . . ."])

try:
    coord = obj._check_left(1, 3)
    assert (coord == (1, 0))
    print("Left 2 Passed")
except:
    print("Left 2 Failed")

obj = othello.Othello(
    3, 5, "B", ">",
    [". . . . . .", ". W W W W B", ". . . . . .", ". . . . . ."])
コード例 #12
0
 def __init__(self, master=None, couleur=oth.NOIR):
     tk.Frame.__init__(self, master)
     self.master = master
     self.jeu = oth.Othello()
     self.joueur = couleur  #self.joueur est la couleur du joueur, self.jeu.joueur est la couleur de celui dont c'est le tour
     self.create_widgets()
コード例 #13
0
# This file is executed on every boot (including wake-boot from deepsleep)

import gc
#import webrepl
import network
import esp
import othello
esp.osdebug(None)
#webrepl.start()
gc.collect()

st_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)

ap_if.ifconfig(('6.6.6.1', '255.255.255.128', '6.6.6.1', '8.8.8.8'))
ap_if.config(essid='esp_mpc')
ap_if.config(password='******')

#st_if.active(1)
#st_if.connect('ESSID', 'password')

game1 = othello.Othello()
game1srv = othello.OthelloServer(game1)
コード例 #14
0
# Fonts
OPEN_SANS = "./assets/OpenSans-Regular.ttf"
UNIQUE = "./assets/Unique.ttf"
smallFont = pygame.font.Font(OPEN_SANS, 20)
mediumFont = pygame.font.Font(UNIQUE, 28)
largeFont = pygame.font.Font(UNIQUE, 40)

# Compute board size
BOARD_PADDING = 20
board_width = ((2 / 3) * width) - (BOARD_PADDING * 2)
board_height = height - (BOARD_PADDING * 2)
cell_size = int(min(board_width / 8, board_height / 8))
board_origin = (BOARD_PADDING, BOARD_PADDING)

game = o.Othello()
ai_turn = False

version = "Beta 1.0.0 v2"

user = None

Instructions = False

i = [
    "Take turns against the AI",
    "Make a move by clicking on an empty tile",
    "All pieces between your move and any other friendly piece will convert",
    "Your move must convert at least one other tile",
    "Win by ending the game with the most pieces of your color on the board",
    "The game ends when either all tiles are filled or no moves are left",
コード例 #15
0
ファイル: Othello_gui.py プロジェクト: madhugovind/Python
    def _on_version_label(self) -> None:
        # When the user clicks the FULL button, we pop up a GameDialog.
        # Since we've already encapsulate all of that in the GameDialog
        # class, all we need to do is create a GameDialog object, ask it
        # to show itself, and then ask it afterward what happened.
        #
        # Note that the call to show() isn't going to return until the user
        # has dismissed the dialog box.
        dialog = GameDialog()
        dialog.show()

        # After the dialog box is dismissed, we'll check if it was the PLAY
        # or the QUIT button that got clicked.  If PLAY was clicked, we'll
        # change the version label's text by setting its control variable.
        if dialog.was_play_clicked():
            self.row_num = dialog.return_row()
            self.col_num = dialog.return_col()
            self.player_turn = dialog.return_turn()
            self.win_crit = dialog.return_win_crit()
            self.white_placed = dialog.return_white_placed()
            self.black_placed = dialog.return_white_placed()
            self.ogame = othello.Othello(self.col_num, self.row_num,
                                         self.win_crit, self.player_turn)
            self.white_counter = 0
            self.black_counter = 0
            self.game_over = False

            self.version_button.destroy()
            self._canvas = tkinter.Canvas(master=self._root_window,
                                          width=self.col_num * 100,
                                          height=self.row_num * 100,
                                          background="GREEN")
            self._canvas.grid(row=1,
                              column=0,
                              columnspan=3,
                              padx=10,
                              pady=10,
                              sticky=tkinter.N + tkinter.S + tkinter.E +
                              tkinter.W)
            self.width = self._canvas.winfo_width()
            self.height = self._canvas.winfo_height()
            self.turn = tkinter.StringVar()
            self.turn.set("TURN: {}".format(self.ogame.get_turn()))
            self.bscore = tkinter.StringVar()
            self.bscore.set("B: {}".format(self.ogame.count_black_tiles()))
            self.wscore = tkinter.StringVar()
            self.wscore.set("W: {}".format(self.ogame.count_white_tiles()))

            self.turn_label = tkinter.Label(master=self._root_window,
                                            textvariable=self.turn)
            self.turn_label.grid(row=0,
                                 column=0,
                                 pady=5,
                                 sticky=tkinter.N + tkinter.S + tkinter.E +
                                 tkinter.W)
            self._root_window.rowconfigure(0, weight=0)
            self._root_window.columnconfigure(0, weight=1)

            self.bscore_label = tkinter.Label(master=self._root_window,
                                              textvariable=self.bscore)
            self.bscore_label.grid(row=0,
                                   column=1,
                                   pady=5,
                                   sticky=tkinter.N + tkinter.S + tkinter.E +
                                   tkinter.W)
            self._root_window.rowconfigure(0, weight=0)
            self._root_window.columnconfigure(1, weight=1)

            self.wscore_label = tkinter.Label(master=self._root_window,
                                              textvariable=self.wscore)
            self.wscore_label.grid(row=0,
                                   column=2,
                                   pady=5,
                                   sticky=tkinter.N + tkinter.S + tkinter.E +
                                   tkinter.W)
            self._root_window.rowconfigure(0, weight=0)
            self._root_window.columnconfigure(2, weight=1)

            self._canvas.bind("<Configure>", self.adjust_screen_dimensions)
            self._canvas.bind("<Button-1>", self.check_and_switch)
コード例 #16
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.GameName = QLabel()
        self.GameName.setText("Othello Game")
        self.GameName.setAlignment(Qt.AlignCenter)

        self.turnstatus = QLabel()
        self.turnstatus.setText("흑돌 차례")
        self.turnstatus.setAlignment(Qt.AlignCenter)

        self.gameerror = QLabel()
        self.gameerror.setAlignment(Qt.AlignCenter)

        self.blackplayer = QLabel()
        self.blackplayer.setText("●")
        self.whiteplayer = QLabel()
        self.whiteplayer.setText("○")
        self.blackstatus = QLabel()
        self.blackstatus.setText(str(2))
        self.whitestatus = QLabel()
        self.whitestatus.setText(str(2))

        self.statusLayout = QHBoxLayout()
        self.statusLayout.addWidget(self.blackplayer)
        self.statusLayout.addWidget(self.blackstatus)
        self.statusLayout.addWidget(self.whiteplayer)
        self.statusLayout.addWidget(self.whitestatus)

        self.buttonList = [[QToolButton() for i in range(8)] for j in range(8)]

        self.buttonLayout = QGridLayout()
        for i in range(8):
            for j in range(8):
                self.buttonLayout.addWidget(self.buttonList[i][j], i, j)
                self.buttonLayout.setSizeConstraint(QLayout.SetFixedSize)

        for i in range(8):
            for j in range(8):
                self.buttonList[i][j].clicked.connect(self.ButtonClicked)
                self.x = i
                self.y = j

        self.undoButton = QPushButton()
        self.undoButton.setText("실행취소")

        self.newgameButton = QPushButton()
        self.newgameButton.setText("새 게임")

        self.settingLayout = QHBoxLayout()
        self.settingLayout.addWidget(self.undoButton)
        self.settingLayout.addWidget(self.newgameButton)

        mainLayout = QGridLayout()
        mainLayout.addWidget(self.GameName, 0, 0)
        mainLayout.addWidget(self.turnstatus, 1, 0)
        mainLayout.addWidget(self.gameerror, 2, 0)
        mainLayout.addLayout(self.statusLayout, 3, 0)
        mainLayout.addLayout(self.buttonLayout, 4, 0)
        mainLayout.addLayout(self.settingLayout, 5, 0)

        self.game = othello.Othello()
        self.undogame = undogame.UndoTurn()
        self.newgameButton.clicked.connect(self.settingNewGame)
        self.undoButton.clicked.connect(self.UndoGame)
        self.game.New_Game()  # 게임을 시작한다
        self.setBoardGUI(self.game.getboard())

        self.setLayout(mainLayout)
        self.setWindowTitle("Othello")