Example #1
0
def startup(moveMethod, botName="PurdueBot"):
    parser = argparse.ArgumentParser()
    parser.add_argument('-name', metavar='str', type=str, default=os.environ.get('GENERALS_BOT_NAME', botName), help='Name of Bot')
    parser.add_argument('-g', '--gameType', metavar='str', type=str, choices=["private","1v1","ffa","team"], default="1v1", help='Game Type: private, 1v1, or ffa')
    parser.add_argument('-r', '--roomID', metavar='str', type=str, default="EklipZTest2", help='Private Room ID (optional)')
    parser.add_argument('--no-ui', action='store_false', help="Hide UI (no game viewer)")
    parser.add_argument('--public', action='store_true', help="Run on public (not bot) server")
    args = vars(parser.parse_args())

    if (moveMethod == None):
    	raise ValueError("A move method must be supplied upon startup")
    
    bot_base.GeneralsBot(moveMethod, name=args['name'], gameType=args['gameType'], privateRoomID=args['roomID'], gameViewer=args['no_ui'], public_server=args['public'])
Example #2
0
def startup(moveMethod, moveEvent=None, botName="PurdueBot"):
    parser = argparse.ArgumentParser()
    parser.add_argument('-name',
                        metavar='str',
                        type=str,
                        default=os.environ.get('GENERALS_BOT_NAME', botName),
                        help='Name of Bot')
    parser.add_argument('-g',
                        '--gameType',
                        metavar='str',
                        type=str,
                        choices=["private", "1v1", "ffa"],
                        default=os.environ.get('GENERALS_BOT_MODE', 'private'),
                        help='Game Type: private, 1v1, or ffa')
    parser.add_argument('-r',
                        '--roomID',
                        metavar='str',
                        type=str,
                        default=os.environ.get("GENERALS_BOT_ROOM_ID",
                                               "PurdueBot"),
                        help='Private Room ID (optional)')
    parser.add_argument('-c',
                        '--command',
                        metavar='str',
                        type=str,
                        default="",
                        help='Initial Setup Command (optional)')
    parser.add_argument('--no-ui',
                        action='store_false',
                        help="Hide UI (no game viewer)")
    parser.add_argument('--public',
                        action='store_true',
                        help="Run on public (not bot) server")
    args = vars(parser.parse_args())

    if moveMethod == None:
        raise ValueError("A move method must be supplied upon startup")

    bot_base.GeneralsBot(moveMethod,
                         moveEvent=moveEvent,
                         name=args['name'],
                         gameType=args['gameType'],
                         privateRoomID=args['roomID'],
                         showGameViewer=args['no_ui'],
                         public_server=args['public'],
                         start_msg_cmd=args['command'])
    _bot._collect_path = _collect_path


def move_collect_to_path():
    global _collect_path

    try:
        source = _collect_path[0]
        dest = _collect_path[1]
    except IndexError:
        return False

    if (source.tile == _map.player_index and
        (dest.tile == _map.player_index or source.army > dest.army + 1)):
        place_move(source, dest)
        return True

    return False


######################### Main #########################

# Start Game
bot_base.GeneralsBot(make_move,
                     name="PurdueBot-P",
                     gameType="private",
                     privateRoomID="PurdueBot"
                     )  # Private Game - http://generals.io/games/HyI4d3_rl
#bot_base.GeneralsBot(make_move, name="PurdueBot-P", gameType="1v1")
#bot_base.GeneralsBot(make_move, name="PurdueBot-P", gameType="ffa")
Example #4
0
	target = _bot.find_closest_target(source)
	path = _bot.find_path(source=source, dest=target)

	army_total = 0
	for tile in path: # Verify can obtain every tile in path
		if (tile.tile == _map.player_index):
			army_total += (tile.army - 1)
		elif (tile.army+1 > army_total): # Cannot obtain tile, draw path from largest city to largest tile
			source = _bot.find_city(includeGeneral=True)
			target = _bot.find_largest_tile()
			if (source and target and source != target):
				path = _bot.find_path(source=source, dest=target)
			break

	# Place Move
	_path = path
	_bot._path = path
	(move_from, move_to) = _bot.path_forward_moves(path)
	if (move_from != None):
		_bot.place_move(move_from, move_to)
		return True

	return False

######################### Main #########################

# Start Game
bot_base.GeneralsBot(make_move, name="[Bot]KingTrav", gameType="private", privateRoomID="KingTrav") # Private Game - http://generals.io/games/HyI4d3_rl
#bot_base.GeneralsBot(make_move, name="PurdueBot-B", gameType="1v1")
#bot_base.GeneralsBot(make_move, name="PurdueBot-B", gameType="ffa")