def judge(n_move, verbose=False): f = open(path, "a") N = 5 piece_type, previous_board, board = readInput(N) go = GO(N) go.verbose = verbose go.set_board(piece_type, previous_board, board) go.n_move = n_move try: action, x, y = readOutput() except: print("output.txt not found or invalid format") print("output.txt not found or invalid format", file=f) sys.exit(3 - piece_type) if action == "MOVE": if not go.place_chess(x, y, piece_type): print('Game end.') print('The winner is {}'.format('X' if 3 - piece_type == 1 else 'O')) print('Game end.', file=f) print('The winner is {}'.format('X' if 3 - piece_type == 1 else 'O'), file=f) sys.exit(3 - piece_type) go.died_pieces = go.remove_died_pieces(3 - piece_type) if verbose: go.visualize_board() print() print(file=f) if go.game_end(piece_type, action): result = go.judge_winner() if verbose: print('Game end.') print('Game end.', file=f) if result == 0: print('The game is a tie.') print('The game is a tie.', file=f) else: print('The winner is {}black score {} white score {}'.format( 'X' if result == 1 else 'O', go.score(1), go.score(2))) print('The winner is {}black score {} white score {}'.format( 'X' if result == 1 else 'O', go.score(1), go.score(2)), file=f) sys.exit(result) piece_type = 2 if piece_type == 1 else 1 if action == "PASS": go.previous_board = go.board writeNextInput(piece_type, go.previous_board, go.board) f.close() sys.exit(0)
def judge(self, n_move, verbose): N = 5 piece_type, previous_board, board = readInput(N) go = GO(N) go.verbose = verbose go.set_board(piece_type, previous_board, board) go.n_move = n_move try: action, x, y = readOutput() except: cond_print(verbose, "output.txt not found or invalid format") return (3 - piece_type) if action == "MOVE": if not go.place_chess(x, y, piece_type): cond_print(verbose, 'Game end.') cond_print( verbose, 'The winner is {}'.format('X' if 3 - piece_type == 1 else 'O')) return (3 - piece_type) go.died_pieces = go.remove_died_pieces(3 - piece_type) if go.game_end(piece_type, action): result = go.judge_winner() if verbose: cond_print(verbose, 'Game end.') if result == 0: cond_print(verbose, 'The game is a tie.') else: cond_print( verbose, 'The winner is {}'.format('X' if result == 1 else 'O')) return (result) piece_type = 2 if piece_type == 1 else 1 if action == "PASS": go.previous_board = go.board writeNextInput(piece_type, go.previous_board, go.board) return (0)