def play(self,board): policy = int(input("Please take you action:")) while(not core.is_policy_avaliable(board,policy)): policy = int(input("Action is not valid, try another one:")) board[policy]=self.label core.print_board(board)
def play(self,board): own_vision=[i/self.label for i in board] #policy=ai.minimax_decision(own_vision) (policy,_)=ai.best_policy_and_util(own_vision,core.SELF) print ("AI is making decision: ", policy) if (core.is_policy_avaliable(board,policy)): board[policy]=self.label core.print_board(board)
def play(strategy_X, strategy_O, first=core.MAX, silent=True): """ Plays strategy_X vs. strategy_O, beginning with first in one game. Returns X, O or TIE as a result (string) The functions make_move, next_player and terminal_test are implemented elsewhere (e.g. in core.py). The current implementation uses a 9-char string as the state, but that is not exposed at this level. """ board = core.start_state player = first current_strategy = {core.MAX: strategy_X, core.MIN: strategy_O} while player is not None: move = current_strategy[player](board, player) board = core.make_move(board, player, move) player = core.next_player(board, player) if not silent: core.print_board(board) return core.terminal_test(board)
def human(player, board): print(core.print_board(board)) print('Your move?') while True: move = input('> ') if move and check(int(move), player, board): return int(move) elif move: print('Illegal move--try again.')
def ply(self): """ make a ply Parameters: """ core.print_board(self.board) is_first_hand_turn = True while (core.is_playable(self.board)): if (is_first_hand_turn): self.firsthand.play(self.board) else: self.lasthand.play(self.board) is_first_hand_turn = not is_first_hand_turn else: (_, winner) = core.get_game_state(self.board) if (winner == self.firsthand.label): print("first hand win") elif (winner == self.lasthand.label): print("last hand win") else: print("tie!")
def main(): try: black, white = get_players() board, score = core.play(black, white) except core.IllegalMoveError as e: print(e) return except EOFError as e: print('Goodbye.') return print('%s wins!' % ('Black' if score > 0 else 'White')) print(core.print_board(board)) print('Final score:', score)