예제 #1
0
 def startGame(self, game="private"):
     if game == "1v1":
         g = generals.Generals('ry0FVyx_g', 'frank', '1v1')
     elif game == "ffa":
         g = generals.Generals('ry0FVyx_g', 'frank', 'ffa')
     elif game == "private":
         self.roomID = raw_input("Please enter the room id: ")
         g = generals.Generals('ry0FVyx_g', 'frank', 'private', self.roomID)
     elif game == "2v2":
         g = generals.Generals('ry0FVyx_g', 'frank', 'team')
     else:
         print("Please input one of the following game types: ")
         print("1v1, ffa, private, 2v2")
예제 #2
0
def play_game(gameid):
    ai = Instance(m, MODE_INFERENCE)
    if gameid == '1v1':
        g = generals.Generals(userid, username, '1v1')
    else:
        g = generals.Generals(userid, username, 'private', gameid)

    for update in g.get_updates():
        if 'complete' in update and update['complete']:
            logging.info(str(update))
            break
        if update['turn'] >= 2000:
            break
        ai.update(update_to_observe(update))
        move = ai.predict()
        ai.state.choseMove(move)

        assert len(move) == 0 or len(move) == 2
        if len(move) == 2:
            g.moveIndices(move[0], move[1])
예제 #3
0
                        type=str,
                        default="viz0",
                        help='id for the game')
    parser.add_argument('--model_path',
                        type=str,
                        default="reinforce.mdl",
                        help='path of a3c trained model')
    args = parser.parse_args()

    model = ActorCritic.ActorCritic()
    model.load_state_dict(torch.load(args.model_path))
    # model = model.eval()
    init_state = False

    # private game
    g = generals.Generals(args.user_id, args.username, 'private', args.game_id)

    for update in g.get_updates():
        start_time = time.time()
        state = gen_state(update)
        dims = state.shape[2], state.shape[3]

        label_map = np.array(update['tile_grid'])
        army_map = np.array(update['army_grid'])

        army_map = state[0, 0, ...]
        label_mask = army_map > 0
        full_label_mask = np.concatenate(
            [label_mask[np.newaxis, ...] for i in range(8)])

        if not init_state:
예제 #4
0
import generals
import heapq

# 1v1
#g = generals.Generals('ry0FVyx_g', 'frank', '1v1')

# ffa
# g = generals.Generals('your userid', 'your username', 'ffa')

# private game
roomID = raw_input("Please enter the room id: ")
#print(roomID)

g = generals.Generals('ry0FVyx_g', 'frank', 'private', roomID)

# 2v2 game
# g = generals.Generals('your userid', 'your username', 'team')


class Tile:
    def __init__(self):
        self.state = generals.FOG  # what is on the tile
        self.visited = False  # while traversing, marks if visited
        self.coords = []  # coordinates in grid
        self.up = None  # Node above it
        self.down = None  # Node below it
        self.left = None  # Node to left of it
        self.right = None  # Node to right of it
        self.army = 0  # Number of troops on the tile (- means good)
        self.searchDist = 0  #
        self.searchPrev = None
#!/bin/python
import generals
import logging

logging.basicConfig(level=logging.DEBUG)

# 1v1
g = generals.Generals('your userid', 'your username', '1v1')

# ffa
# g = generals.Generals('your userid', 'your username', 'ffa')

# private game
# g = generals.Generals('your userid', 'your username', 'private', 'your gameid')

# 2v2 game
# g = generals.Generals('your userid', 'your username', 'team')

for update in g.get_updates():

    # get position of your general
    pi = update['player_index']
    try:
        y, x = update['generals'][pi]
    except KeyError:
        break

    # move units from general to arbitrary square
    for dy, dx in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        if (0 <= y+dy < update['rows'] and 0 <= x+dx < update['cols']
                and update['tile_grid'][y+dy][x+dx] != generals.MOUNTAIN):