コード例 #1
0
def start_skill():
    """
    Resets CNN for new game.

    Returns
    -------
    question
    """
    global cnn
    global state
    print("Skill started")
    state = None
    root = Node(Go.GameState(size=SIZE, komi=4))
    cnn = Go_CNN(root)
    return question("I'll begin. Let me know when you are ready.")
コード例 #2
0
def create_game(init_time=120, filepath="mc.txt"):
    """
    Creates Monte Carlo and plays through for init_time seconds. Saves to txt file.

    Parameters
    ----------
    init_time: int
        seconds for which initialization will occur
    filepath: String
        path to txt file

    Returns
    -------
    None
    """
    root = Node(Go.GameState())
    monte = MonteCarlo(root, initial_time=init_time)
    with open(filepath, "wb") as f:
            pickle.dump(monte, f)
コード例 #3
0
def start_game(reset=False, size=5, init_time=240):
    """
    Starts single player game, with computer going first, using python console.

    <<< USED FOR DEBUGGING PURPOSES, MAY NOT BE FULLY FUNCTIONAL >>>

    Parameters
    ----------
    reset: Boolean
        True: Create and train new Monte Carlo
        False: Load Monte Carlo from txt
    size: int
        size of board
    init_time: int
        seconds for which initialization will occur

    Returns
    -------
    int: winner
    """
    filepath = "mc_" + str(size) + "x" + str(size) + ".txt"
    sys.setrecursionlimit(3000)
    if reset:
        root = Node(Go.GameState(size))
        monte = MonteCarlo(root, initial_time=init_time)
        with open(filepath, "wb") as f:
            pickle.dump(monte, f)
    else:
        t0 = time.time()
        with open(filepath, "rb") as f:
            monte = pickle.load(f)
        print(time.time() - t0)
    print("Computer: I'll start.")
    root = monte.root
    root.content.captures = 0
    state = root.content
    while state.winner() == 0:
        state = monte.get_play()[0].content
        state.paint()
        if state.winner() != 0:
            break
        result = False
        while result is False:
            r = ""
            c = ""
            while not (len(r) > 0 and (r.isdigit() or r.upper() == "P")):
                r = input("Enter row or P to pass: "******"P":
                result = "P"
            else:
                while not (len(c) > 0 and c.isdigit()):
                    c = input("Enter column: ")
                result = (int(r), int(c))
            result = monte.update(result)
            if result is False:
                continue
            state = result.content
            state.paint()

    scores = state.score()
    winner = state.winner()
    if winner < 0:
        print("Tie reached.")
    elif winner == 1:
        print("Computer wins.")
    else:
        print("Player wins.")
    print("The score was " + str(scores[0]) + "-" + str(scores[1]) + ".")
    return winner
コード例 #4
0
ファイル: CNN.py プロジェクト: lilianluong16/cogworks_team4
def start_game(param):
    """
    Starts single player game, with computer going first, using python console.

    CNN IMPLEMENTATION

    <<< USED FOR DEBUGGING PURPOSES, MAY NOT BE FULLY FUNCTIONAL >>>

    Parameters
    ----------
    reset: Boolean
        True: Create and train new Monte Carlo
        False: Load Monte Carlo from txt
    size: int
        size of board
    init_time: int
        seconds for which initialization will occur

    Returns
    -------
    int: winner
    """
    print("Computer: I'll start.")
    root = Node(Go.GameState(size=9, komi=0))
    cnn = Go_CNN(root, param)
    state = root.content
    while state.winner() == 0:
        state = cnn.get_play()[0].content
        state.paint(False)
        if state.winner() != 0:
            break
        result = False
        while result is False:
            r = ""
            c = ""
            while not (len(r) > 0 and (r.isdigit() or r.upper() == "P")):
                r = input("Enter row or P to pass: "******"q":
                return
            if r.upper() == "P":
                result = "P"
            else:
                while not (len(c) > 0 and c.isdigit()):
                    c = input("Enter column: ")
                result = (int(r), int(c))
            result = cnn.update(result)
            if result is False:
                continue
            state = result.content
            state.paint(False)

    scores = state.score()
    winner = state.winner()
    if winner < 0:
        print("Tie reached.")
    elif winner == 1:
        print("Computer wins.")
    else:
        print("Player wins.")
    print("The score was " + str(scores[0]) + "-" + str(scores[1]) + ".")
    return winner