def dummy_game(board): g = reversi.Reversi() g.board = [[0 for x in range(8)] for x in range(8)] for k, v in board.items(): x, y = k g.board[x][y] = v return g
def __init__(self, root): super().__init__() self.root = root self.game = model.Game(NBR_ROWS, NBR_COLS) self.game_board = self.game.get_board() self.root.geometry("600x600") self._reversi = reversi.Reversi(self.game, self.root, HEIGHT, WIDTH) self.window = self._reversi.get_board() self.initUI() self.initGame()
def main(): # reversi program ## game initialize game = reversi.Reversi([ reversi.Player('gray1', 'AI', bot.fixed_mini_max, name='BOT1', max_depth=2, playout_count=100, evaluation=bot.static_corner_score), reversi.Player('gray99', 'AI', bot.mini_max, name='BOT2', max_depth=2, playout_count=100, evaluation=bot.static_board_score) ], area=8) game.game_init() # game main loop score = '' # 棋譜 while True: # print('PLAYER {} TURN'.format(game.ORDER.index(game.turn)+1)) pos = game.turn.rogic(game) print('{} put position -> ({}, {})'.format(game.stone_num, *pos)) score += chr(ord('A') + (pos[0] - 1)) + str(pos[1]) game.put_stone(pos, game.turn) game.nextturn() game.putlist = game.make_putlist(game.turn) pass_player = game.pass_check() if len(pass_player) == len(game.ORDER): # ゲーム終了 game.end() print(score) return else: for p in pass_player: # print('\n\nGAME INFO\nPLAYER {}, PASS\n'.format(game.ORDER.index(game.turn)+1)) pass return
def test_weird_edge_cases(self): g = reversi.Reversi() g.board = [ [0, 1, 0, 1, 2, 1, 0, 0], [0, 2, 2, 2, 2, 1, 0, 0], [0, 0, 2, 2, 2, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 2, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], ] self.assertEqual(2, g.place_piece(0, 0, live_mode=False))
def __init__(self): self.game = reversi.Reversi() self.ai = ai_adapter self.ai.setLevel(0) self.humanSide = reversi.BLACK # Create layout super(ReversiUI, self).__init__() self.master = QHBoxLayout() self.controlBar = QVBoxLayout() self.infoBar = QVBoxLayout() self.score_str = "{}" self.scoreLabelA = ScoreIndicator(reversi.BLACK) self.scoreLabelB = ScoreIndicator(reversi.WHITE) self.painter = PaintArea() self.painter.setFocusPolicy(Qt.StrongFocus) self.init_ui()
def main(): # reversi program ## game initialize game = reversi.Reversi([ reversi.Player('gray1', 'Player', name='PLAYER'), reversi.Player('gray99', 'AI', bot.soft_max, name='BOT', max_depth=4, playout_count=100, evaluation=bot.static_corner_score) ], area=8, mode='gui') game.game_init() game.window.mainloop() return
def test_and_plot_win_rate(dqn_player, save_name="./fig/test_plot.pdf", game_num=1000, tqdm=False): # train用情報退避 train_record = dqn_player.record dqn_player.record = [] train_eps = dqn_player.eps dqn_player.eps = 0 train_memory = dqn_player.memory dqn_player.memory = Memory(size=64) random_player = reversi.player.RandomPlayer("乱太郎") if tqdm: for i in tqdm(range(game_num)): if np.random.random() < 0.5: white = random_player black = dqn_player else: white = dqn_player black = random_player game = reversi.Reversi(white, black) game.main_loop(print_game=False) else: print("battle with random...") for i in range(game_num): if np.random.random() < 0.5: white = random_player black = dqn_player else: white = dqn_player black = random_player game = reversi.Reversi(white, black) game.main_loop(print_game=False) wining_DQN = np.array(dqn_player.record) == 1 plt.grid(True) plt.ylim(0, 1) final_win_rate = np.cumsum(wining_DQN)[len(np.cumsum(wining_DQN)) - 1] / len(wining_DQN) title = [] title.append("Win_rate (Battle with random(test))") if dqn_player.PER: title.append("Final = {}, alpha={}, beta={}".format( round(final_win_rate, 4), alpha, beta)) else: title.append("Final = {}".format(round(final_win_rate, 4))) plt.ylim(0, 1) plt.title("\n".join(title)) plt.xlabel("episode") plt.ylabel("win_rate") plt.plot(np.cumsum(wining_DQN) / (np.arange(len(wining_DQN)) + 1)) plt.savefig(save_name, bbox_inches="tight") plt.show() # train用情報復帰 dqn_player.record = train_record dqn_player.eps = train_eps dqn_player.memory = train_memory
def __init__(self): super(Engine_v1, self).__init__() self.resources = {} #create game self.game = reversi.Reversi()
def __init__(self): super(Engine_v1, self).__init__() self.resources = {} self.keys_down = {} self.game = reversi.Reversi()
import sys import reversi from tqdm import tqdm player1 = reversi.player.RandomPlayer('ランダム1') player2 = reversi.player.RandomPlayer('ランダム2') game = reversi.Reversi(player1, player2) game.main_loop(print_game=True)
if not Highscore.load(score_path): print("High score kunde inte läsas in. Sätter till 0 poäng.\n") try: size = interface.get_int( "Skriv storleken på brädet (måste vara delbart med två och ligga mellan 4 och 26): ", "Du måste skriva ett tal!") while not 4 <= size <= 26 or size % 2 == 1: print("Måste vara delbart med två och ligga mellan 4 och 26!") size = interface.get_int( "Skriv storleken på brädet (måste vara delbart med två och ligga mellan 4 och 26): ", "Du måste skriva ett tal!") print() board = reversi.Board(size) game = reversi.Reversi(board) bot = Bot(game, -player) winner = None while not winner: interface.display_board(board) if game.get_turn() == player: print("Din tur (%s) att spela!" % colors[player]) if interface.should_skip(): game.skip() else: success = False while not success: row, col = interface.get_row_col(size)
def __init__(self, black_player, white_player): self.reversi = reversi.Reversi(black_player, white_player)