Ejemplo n.º 1
0
def load_default_player():
    path = read_config('go.config')["default-player"]
    spec = importlib.util.spec_from_file_location("module.name", path)
    foo = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(foo)
    inner = foo.GoPlayerRandom()
    player = GoPlayerContract(inner)
    return player
Ejemplo n.º 2
0
    ## Read Stdin
    objs = json_parse_stdin()

    ## Establish Connection
    config = read_config('go.config')
    TCP_IP = config["IP"]
    TCP_PORT = config["port"]

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((TCP_IP, TCP_PORT))
    s.settimeout(60)
    s.listen(1)
    conn, addr = s.accept()

    player_inner = GoPlayerNetwork(conn)
    player = GoPlayerContract(player_inner)

    output = []
    for obj in objs:
        ret = execute_input(player, obj)
        if ret:
            output.append(ret)
        if ret == GO_CRAZY:
            break

    ## Close the connection
    conn.send(json.dumps(-1).encode('utf-8'))
    try_shutdown(conn, socket.SHUT_RDWR)
    conn.close()
    try_shutdown(s, socket.SHUT_RDWR)
    s.close()
Ejemplo n.º 3
0
        try:
            output = execute_input(player, data)
            s.send(json.dumps(output).encode('utf-8'))
        except:
            output = GO_CRAZY
            s.send(json.dumps(output).encode('utf-8'))
            break

## creates socket
config = read_config('go.config')
TCP_IP = config["IP"]
TCP_PORT = config["port"]
config1 = read_config('go-player.config')
N = config1["depth"]
BUFFER_SIZE = 55520
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

for i in range(30):
    try:
        s.connect((TCP_IP, TCP_PORT))
        break
    except:
        time.sleep(1)
        continue

## instantiate remote player
player = GoPlayerAdv(N)
player_contract = GoPlayerContract(player)
receive_and_send(s, player_contract)
try_shutdown(s, socket.SHUT_RDWR)
s.close()
Ejemplo n.º 4
0
from stone import StoneEnum, make_stone
from go_player_file import GoPlayerFile
from go_player import GoPlayerContract
from go_referee import GoReferee
from go_ref_formatter import format_obj
from referee_formatter import format_pretty_json

if __name__ == "__main__":
    objs = json_parse_stdin()

    ## Initialize Stones, Points
    names, points = objs[:2], [parse_move(x) for x in objs[2:]]
    board = Board([[make_stone(None) for i in range(BOARD_DIM)]
                   for j in range(BOARD_DIM)])

    ## Initialize Players
    inner_player1 = GoPlayerFile(points[::2])
    player1 = GoPlayerContract(inner_player1)
    player1.register(names[0])
    player1.receive_stone(StoneEnum.BLACK)

    inner_player2 = GoPlayerFile(points[1::2])
    player2 = GoPlayerContract(inner_player2)
    player2.register(names[1])
    player2.receive_stone(StoneEnum.WHITE)

    ## Initialize Go Ref
    go_referee = GoReferee([player1, player2])
    output = go_referee.play_game()
    raw_output = list(map(format_obj, output))
    print(format_pretty_json(raw_output))
Ejemplo n.º 5
0
def load_network_player(conn):
    inner = GoPlayerNetwork(conn)
    player = GoPlayerContract(inner)
    return player