summaryrefslogtreecommitdiff
path: root/main.py
blob: c0e9a2167c60ac4d6728741d44706610d9ed3bd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from agarnet.agarnet import client
from agarnet.agarnet import utils
import pygame
from pygame import gfxdraw
from pygame.locals import *
import sys
import math
import time
import random
import gui
import stats
from subscriber import EnhancingSubscriber
from interval_utils import *
from strategy import *

# global vars
sub = EnhancingSubscriber()
c = client.Client(sub)
sub.set_client(c)
stats = stats.Stats(c)
            
try:
    nick = sys.argv[2]
except:
    nick = "test cell pls ignore"

for i in range(1,10): # 10 connection attempts
    print("trying to connect, attempt "+str(i))
    try:
        # find out server and token to connect
        try:
            token = sys.argv[1]
            addr, *_ = utils.get_party_address(token)
            print("using party token")

        except:
            addr, token, *_ = utils.find_server()
            print("joining random game")

        # connect
        c.connect(addr,token)
        c.send_facebook(
                    'g2gDYQFtAAAAEKO6L3c8C8/eXtbtbVJDGU5tAAAAUvOo7JuWAVSczT5Aj0eo0CvpeU8ijGzKy/gXBVCxhP5UO+ERH0jWjAo9bU1V7dU0GmwFr+SnzqWohx3qvG8Fg8RHlL17/y9ifVWpYUdweuODb9c=')
        break
    except:
        c.disconnect()


c.player.nick=nick


# initialize GUI
gui.set_client(c)

# initialize strategy
strategy = Strategy(c)

autorespawn_counter = 60

# main loop
while gui.running:
    c.on_message()
    
    gui.draw_frame()
    
    if len(list(c.player.own_cells)) > 0:
        target = strategy.process_frame()

        if gui.bot_input:
            c.send_target(target[0], target[1])

        stats.process_frame()

    gui.update()

    if not c.player.is_alive:
        if autorespawn_counter == 0:
            c.send_respawn()
            autorespawn_counter = 60
        else:
            autorespawn_counter-=1

stats.save("stats.pickle")

print("bye")