Пример #1
0
def init(i_play_as):
    global fl1, fl2, game_board, old_move, bot
    fl1 = 'x'
    fl2 = 'o'
    game_board = Board()
    old_move = (-1, -1)
    bot = Player40()
    if i_play_as == 'o':
        temp_board_status = copy.deepcopy(game_board.board_status)
        temp_block_status = copy.deepcopy(game_board.block_status)

        try:
            bot_move = bot.move(game_board, old_move, fl2)
        except Exception:
            print traceback.format_exc()
            WINNER = 'HUMAN'
            MESSAGE = 'INVALID MOVE'
            return game_over((-1, -1), WINNER, MESSAGE)
        if (game_board.block_status != temp_block_status) or (
                game_board.board_status != temp_board_status):
            WINNER = 'HUMAN'
            MESSAGE = 'MODIFIED THE BOARD'
            return game_over(bot_move, WINNER, MESSAGE)
        if game_board.update(old_move, bot_move, fl2) == 'UNSUCCESSFUL':
            WINNER = 'HUMAN'
            MESSAGE = 'INVALID MOVE'
            return game_over(bot_move, WINNER, MESSAGE)

        old_move = bot_move
        game_board.print_board()

        return jsonify({
            'move':
            sermove(old_move),
            'valid':
            sermoves(game_board.find_valid_move_cells(old_move))
        })
    return "yay"
from simulator import Game, Board, Agent

if __name__ == "__main__":
    # Points & Tiled
    points = [[-1, 4, 3, 5, 9, 5, 3, 4, -1], [5, 3, 8, -10, 2, -10, 8, 3, 5],
              [6, 3, 7, 8, 0, 8, 7, 4, 6], [5, 3, 8, -10, 2, -10, 8, 3, 5],
              [-1, 4, 3, 5, 9, 5, 3, 4, -1]]
    tiled = [[0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0, 0],
             [0, 0, 2, 0, 0, 0, 2, 0, 0]]

    # Board(width, height, points, tiled)
    board = Board(9, 5, points, tiled)

    # Agent(TeamID, AgentID, x, y)
    ## Note : The coordinate value is 0 standard
    ## Note : AgentID must be unique value!!
    agents = [
        Agent(1, 1, 2, 0),
        Agent(1, 2, 6, 0),
        Agent(1, 3, 4, 1),
        Agent(2, 4, 2, 4),
        Agent(2, 5, 6, 4),
        Agent(2, 6, 4, 3)
    ]

    # Game(board, agents)
    game = Game(board, agents)

    # GAME.set_action(TeamID, AgentID, dx, dy, remove_panel(default: False))
    game.set_action(1, 1, 1, 1)