Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# !- encoding: UTF-8
import sys
import urllib2
import time
import json
import Queue
import random
from operator import itemgetter, attrgetter
import networkx as nx
import matplotlib.pyplot as plt
token = "トークン"
# クエリー
def query(url):
try:
res = urllib2.urlopen(url)
return res.read()
except Exception, e:
print e
def enter():
url = "http://game.coderunner.jp/enter?token=%s" % token
res = query(url)
if not res == None:
return res
def infoJson():
url = "http://game.coderunner.jp/infoJson?token=%s" % token
res = query(url)
if not res == None:
try:
js = json.loads(res)
return js
except Exception, e:
pass
if __name__ == '__main__':
counter = 0
defeats = []
while True:
qt = time.time()
info = infoJson()
if info == None:
defeats = []
enter()
else:
counter += 1
if counter > 1e8:
counter = 0
enemys = [info['maxhp']] + info['hps']
friends = info['friend']
print counter
print "MyPower:",info['power']
print enemys
print "defeats:",defeats
print "Total Damage:", info['damage']
# Game Start
if len(defeats) == 0:
print "setting"
es = enemys
es.sort()
es.reverse()
defeats = es[0:3]
must = sum(defeats)
# Not Defeat
# info['damage'] < defeats[-1] and dcnt > 0
inn = 0
for d in defeats:
if d in enemys:
inn += 1
print "remain defeats",inn
if inn == 0:
print "defeat update"
es = [info['hp']] + info['hps']
es.sort()
es.reverse()
defeats = es[0:int(len(es)/3)]
if len(defeats) == 0:
defeats = es[0:1]
# Attack
else:
powers = []
MaxPower = 0
for friend in friends:
powers.append(friend['power'])
MaxPower = max(powers)
HP = info['maxhp']
MyPower = info['power']
if HP in defeats:
if MyPower > HP*0.7:
print "Destroy"
enter()
elif MaxPower+1e6 > HP*0.7 and MyPower > 3e7:
print "Destroy"
enter()
else:
print "wait"
et = time.time()
sec = et - qt
print "thinking time", sec
time.sleep(0.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment