Пример #1
0
    def __init__(self, name="AI? More like 愛"):
        # Initialize the Panda Colorfight Client
        self.game = cf.Game()
        self.targets = []
        self.adjacentGold = []
        self.adjacentEnergy = []
        self.emptyGold = []
        self.emptyEnergy = []
        self.started = False
        self.startCell = (-1, -1)
        self.blacklist = set()

        # Attempt to join the game
        if self.game.JoinGame(name):
            self.game.Refresh()
            self.Alina()
            self.FetchInfo()
            self.playing = True
            self.refreshThread = Thread(target=self.Refresh)
            self.refreshThread.start()
            self.playThread = Thread(target=self.Play)
            self.playThread.start()
            self.baseThread = Thread(target=self.Base)
            self.baseThread.start()
            self.stopThread = Thread(target=self.Stop)
            self.stopThread.start()
Пример #2
0
    def __init__(self, name, eval_rules, mode="test"):
        self.mode = mode  # decides which API shall use
        self.eval_rules = eval_rules

        if self.mode == "test":
            self.G = localserver.JoinGame(name)
        else:
            self.G = colorfight.Game()
            self.G.JoinGame(name)
Пример #3
0
def run():
    #restart server
    headers = {'content-type': 'application/json'}
    r = requests.post(hostUrl + 'startgame',
                      data=json.dumps({
                          "admin_password": '',
                          "last_time": 320,
                          "ai_join_time": 80,
                          "ai_only": True,
                          "soft": False
                      }),
                      headers=headers)
    time.sleep(5)
    g = colorfight.Game()
    if g.JoinGame('control'):
        #start subprocesses
        subprocess.call(['./bots.sh'])
        #lag control
        time.sleep(15)
        #setup scores list in case some die
        scores = {}
        g.Refresh()
        for user in g.users:
            if user.id != g.uid:
                scores[user.name] = 0
        #find cell and defend that cell
        x, y = find_cell(g)
        status = g.AttackCell(x, y)
        while g.endTime - g.currTime > 1.5:
            g.Refresh()
        #gather scores in dictionary
        for x in range(30):
            for y in range(30):
                cell = g.GetCell(x, y)
                user = find_user(g, cell.owner)
                if user is not None and user.id != g.uid:
                    if cell.cellType == 'gold':
                        scores[user.name] += 10
                    else:
                        scores[user.name] += 1
        #mutate
        genetic.breed(scores)
        time.sleep(3)
        #restart
        run()
    else:
        print('something went f*****g wrong')
        run()
Пример #4
0
    def __init__(self):
        self.g = colorfight.Game()
        self.isJoined = self.g.JoinGame('namabilly')
        self.my_cell = []
        self.neighbor_cell = []
        self.border_cell = []
        self.my_base = []
        self.energy_cell = []  # 18
        self.gold_cell = []  # 18
        self.my_energy = []
        self.my_gold = []
        self.enemy_base = []
        self.neighbor_enemy = []
        self.on_enemy = 0
        self.on_enemy_cell = []
        self.on_enemy_base = []
        self.on_enemy_base_round = []
        self.getBaseRound = False
        self.target = []
        self.modes = ["energy", "gold", "fast", "safe", "attack", "defend"]
        self.status = {
            'energy': 0,
            'energyGrowth': 0,
            'gold': 0,
            'goldGrowth': 0,
            'cellNum': 1,
            'baseNum': 1,
            'cdTime': 0,
            'isDangerous': False,
            'isTaking': False,
            'mode': 0
        }
        self.graph = []
        self.gr = []
        self.path = []

        # skill content

        # blast
        self.blast_points = []

        # multiattack
        self.multi_points = []
Пример #5
0
# You need to import colorfight for all the APIs
import colorfight
import random
from hashlib import md5
from uuid import uuid1


def gen_random_name():
    m = md5()
    m.update(str(uuid1()))
    return m.hexdigest()[8:16]


if __name__ == '__main__':
    # Instantiate a Game object.
    g = colorfight.Game()
    # You need to join the game using JoinGame(). 'MyAI' is the name of your
    # AI, you can change that to anything you want. This function will generate
    # a token file in the folder which preserves your identity so that you can
    # stop your AI and continue from the last time you quit. 
    # If there's a token and the token is valid, JoinGame() will continue. If
    # not, you will join as a new player.
    if g.JoinGame(gen_random_name()):
        # Put you logic in a while True loop so it will run forever until you 
        # manually stop the game
        while True:
            # Use a nested for loop to iterate through the cells on the map
            for x in range(g.width):
                for y in range(g.height):
                    # Get a cell
                    c = g.GetCell(x,y)
Пример #6
0
 def __init__(self):
     self.g = colorfight.Game()
     self.g.JoinGame('zero')
Пример #7
0
 def __init__(self):
     self.g = colorfight.Game()
     self.g.JoinGame('Anonymous')
Пример #8
0
import petryailib as petry
import colorfight as server
import math

#GLOBAL SETTINGS


def distance(a, b):
	return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)

g = server.Game()


AI=petry.PetryAI(g, "Petry", eval, "battle")

#g.Print()
while True:
	"""
	for s in AI.Soldiers:
		if s.isMine:
			print("MINE:")
			s.print()
		
	print("---")
	"""
	if AI.secureBase():

		max_evalS = 0
		max_evalS_S = None

		for s in AI.Soldiers:
Пример #9
0
 def __init__(self):
     self.g = colorfight.Game()
     self.g.JoinGame('Magikarp')
Пример #10
0
 def __init__(self):
     self.g = colorfight.Game()
     self.g.JoinGame('aaaaAI')