Esempio n. 1
0
import sys, json, time, multiprocessing
sys.path.append('../../3/3.1/src/')
from json_parser import json_parse_stdin
from referee_parser import is_board, is_move, parse_board, parse_move
from referee_formatter import format_score, format_pretty_json
from score_referee import ScoreReferee
from move_referee import MoveReferee


def execute_input(arr):
    if is_board(arr):
        referee = ScoreReferee()
        result = referee.get_score(parse_board(arr))
        return format_score(result)
    elif is_move(arr):
        referee = MoveReferee()
        stone_type, move = parse_move(arr)
        return referee.valid_play(stone_type, move)
    else:
        raise Exception("invalid input")


if __name__ == "__main__":
    objs = json_parse_stdin()
    p = multiprocessing.Pool(len(objs))
    output = list(p.map(execute_input, objs))
    print(format_pretty_json(output))
Esempio n. 2
0
    return referee.execute_move(input_play)


if __name__ == "__main__":
    objs = json_parse_stdin()
    output = []
    referee = GoReferee(player1=GoPlayerBase(objs[0]),
                        player2=GoPlayerBase(objs[1]))
    output.append(BLACK_STONE)
    output.append(WHITE_STONE)

    for obj in objs[2:]:

        raw_out = execute_input(obj, referee)
        output.append(raw_out)

        if referee.game_over:
            if (not referee.winner_declared):
                output.append(referee.get_winners())
                referee.winner_declared = True
            else:
                break

    output = list(filter(None, output))

    formatted_output = []
    for item in output:
        formatted_output.append(format_boards_if_valid(item))

    print(format_pretty_json(formatted_output))
Esempio n. 3
0
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))
Esempio n. 4
0
import sys, multiprocessing, time
sys.path.append('../../../3/3.1/src/')
sys.path.append('../../../4/4.1/src/')
sys.path.append('../../../5/5.1/src/')
from json_parser import json_parse_stdin
from referee_formatter import format_pretty_json
from test_driver_base import execute_input
from go_player_adv import GoPlayerAdv


if __name__ == "__main__":
   def call_exec(obj):
      return execute_input(player, obj)
   player = GoPlayerAdv()
   objs = json_parse_stdin()

   ## First recieve stone, then use threading
   output = list(map(call_exec, objs[0:2]))
   p = multiprocessing.Pool(len(objs) - 2)
   output = output + list(p.map(call_exec, objs[2:]))

   ## Filter for nulls
   filtered = filter(lambda x: x, output)
   print (format_pretty_json(list(filtered)))
Esempio n. 5
0
sys.path.append('../../../4/4.1/src/')
from point import get_raw
from json_parser import json_parse_stdin
from obj_parser import parse_boards, parse_stone
from constants import REGISTER, RECEIVE, MOVE
from referee_formatter import format_pretty_json
from go_player_base import GoPlayerBase


def execute_input(player, arr):
    if arr[0] == REGISTER:
        return player.register()
    elif arr[0] == RECEIVE:
        stone = parse_stone(arr[1])
        player.receive_stone(stone.get_type())
    elif arr[0] == MOVE:
        boards = parse_boards(arr[1])
        output = player.choose_move(boards)
        if isinstance(output, str):
            return output
        return get_raw(output)
    else:
        raise Exception("Invalid name given to execute input")


if __name__ == "__main__":
    player = GoPlayerBase()
    objs = json_parse_stdin()
    output = filter(lambda x: x, [execute_input(player, obj) for obj in objs])
    print(format_pretty_json(list(output)))