def single_player(): player1, _, turn = utility.player_assignment(1) comp = 'Computer' name = player1 unoccupied = [1, 2, 3, 4, 5, 6, 7, 8, 9] board = utility.reset_board() utility.print_board(board) count = 0 for i in range(10): # Taking input from the user b/w 0 to 9 exist = 1 while exist: print(f"{name}'s chance!!!. Choose an unoccupied space :") if name == player1: try: user_input = int(input()) except ValueError: print("Invalid Input") print("!!!Enter Again!!!") exist = 1 continue else: user_input = utility.comp_chance(unoccupied, board, count) if 0 < user_input < 10: # IF true then checking if the space is already occupied if board[user_input] == " ": board[user_input] = turn count += 1 exist = 0 else: print("Space already occupied") exist = 1 else: print("Invalid Input") print("!!!Enter Again!!!") exist = 1 unoccupied.remove(user_input) utility.print_board(board) if count == 9: print("Match Tie") break ans = utility.checking_count(count, board) if ans == 'X' or ans == '0': name = utility.playerName_move[ans] print(f"{name} WINS") break # To interchange players turn, name = utility.interchange_players_turns(player1, comp, name, turn)
def game(p1: str, p2: str, move, board): """ p1 - string - Can be a bot or a user. p2 - string - Always a bot. move - dict[string] - contains info on how a player will move Implements the tic-tac-toe game. """ board = [str(x) for x in range(9)] player = itertools.cycle((p1, p2)) piece = itertools.cycle(("X", "O")) # Default message if outcome is a draw. winner = "No one" print(f"It is {p1}'s turn", end="\n\n") print_board(board) counter = 0 while (counter := counter + 1) <= 9: cur_play, cur_piece = next(player), next(piece) sq = move[cur_play](board, counter - 1, cur_piece) board[sq] = cur_piece print(f"It is {cur_play}'s turn") print_board(board) if iswinner(board, cur_piece): winner = cur_play break
SGF_FILENAME = "0323_result01-0.sgf" TURN_NUMBER = 69 plays = Plays() plays.load_from_sgf(os.path.join(SGF_STORAGE_PATH, SGF_FILENAME)) features = FeatureMap(plays, TURN_NUMBER) print("After move {0}{1}".format( features.turn_number, " (Game ended.)" if features.turn_number == features.total_plays else " / {0}".format(features.total_plays))) print("Next player: {0!r}{1}".format( features.player_color, "" if features.turn_number != features.total_plays else "(Game ended.)")) print("") print("{0}\t{1}") print_features(features) print_int_feature(features.board, features._turns_since_played_plane()) print("") print_int_feature(features.board, features._liberty_planes()) print("") print_int_feature(features.board, features._capture_size_plane()) print("") print_int_feature(features.board, features._self_atari_size_plane()) print("") print_feature(features._label_plane()) print("") print_board(features.board) print("") print("Done.")
SGF_STORAGE_PATH = "." SGF_FILENAME = "0323_result01-0.sgf" TURN_NUMBER = 69 plays = Plays() plays.load_from_sgf(os.path.join(SGF_STORAGE_PATH, SGF_FILENAME)) features = FeatureMap(plays, TURN_NUMBER) print("After move {0}{1}".format(features.turn_number, " (Game ended.)" if features.turn_number == features.total_plays else " / {0}".format( features.total_plays))) print("Next player: {0!r}{1}".format(features.player_color, "" if features.turn_number != features.total_plays else "(Game ended.)")) print("") print("{0}\t{1}") print_features(features) print_int_feature(features.board, features._turns_since_played_plane()) print("") print_int_feature(features.board, features._liberties_plane()) print("") print_int_feature(features.board, features._capture_size_plane()) print("") print_int_feature(features.board, features._self_atari_size_plane()) print("") print_feature(features._label_plane()) print("") print_board(features.board) print("") print("Done.")