Skip to content

Instantly share code, notes, and snippets.

@K-atc K-atc/ai.py
Last active Oct 31, 2015

Embed
What would you like to do?
CodeRunner 2015 予選B https://coderunner.jp/problem-pb.html
#!/usr/bin/env python2
# -*- coding: utf-8 -*
import run
import json
import time
def mtime():
return time.time() * 1000
WAIT_TIME = 4.5
t = mtime()
s_time = t
while True:
ret = run.info()
print ret[0:50]
if ret.find('OUT ROOM') >= 0:
print run.enter()
s_time = mtime()
continue
if ret.find('Error') >= 0:
time.sleep(1.0)
continue
d = json.loads(ret)
hp = int(d['hp'])
print "enemy hp = " + str(d['hp'])
print "経過時間(s) = " + str((mtime() - s_time)/1000)[0:5]
last = mtime() - s_time
if last >= 56000 and last <= 59500: # 1 minutes
time.sleep(0.2)
print "あとすこしで1分経過"
print run.enter()
continue
#print "estimated power = " + str((t - mtime())**2)
print hp - ((t - mtime()) ** 2)
if hp - ((t - mtime()) ** 2) >= 300000: # Will Not Dead
#print "定期攻撃"
time.sleep(WAIT_TIME)
else: # Will Dead
print "あと一撃で仕留める!"
t = mtime()
ret = run.enter()
print ret
if ret.find('GAME') >= 0:
print "ゲーム開始を検出"
s_time = mtime()
continue
#!/usr/bin/env python2
# -*- coding: utf-8 -*
import sys
import run
import json
import time
from pprint import pprint
LIMIT = 12
ret = run.myrank()
#print ret
d = json.loads(ret)
# pprint(d)
for x in d:
print "\x1b[32m" + str(x['room']) + "\t" + str(x['rank']) + "\x1b[0m"
sys.stdout.write(" ")
for y in x['damage']:
sys.stdout.write(str(y) + ", ")
sys.stdout.write("\n")
if LIMIT == 0:
break
LIMIT -= 1
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
import requests
'''
ゲーム概要
----------
「Charge And Hit」は3人1部屋でゲームを行います。ユーザーは入室/攻撃APIをリクエストするとシステムにより各部屋に割り振られます。部屋には10匹の敵が並んでいて、ユーザーは任意のタイミングで一番前の敵を魔法で攻撃します。攻撃によって敵に与えるダメージは「魔法をためた時間」に応じて高くなります。ただし敵の体力を超えるダメージは切り捨てられて体力と等しい値になります。部屋内で与えたダメージの合計値が大きい順に室内順位がつけられ、その室内順位に応じてスコアを得ます。ユーザーは他のユーザーより多くのダメージを与えて、スコアを多く得ることを目指します。
'''
# --- Grobal Conf ---
TOKEN = 'OF14Z3ERYT9O9WVWR2STQHEPMFMFTPE5'
TOKEN = open('./token.txt').read().strip()
ENDPOINT_ENTER = 'http://game.coderunner.jp/enter'
ENDPOINT_INFO = 'http://game.coderunner.jp/infoJson'
ENDPOINT_MYRANK = 'http://game.coderunner.jp/myrankJson'
ENDPOINT_ROOM = 'http://game.coderunner.jp/roomJson'
ENDPOINT_COMMENT = 'http://game.coderunner.jp/comment'
ENDPOINT_CLAR = 'http://game.coderunner.jp/clar'
ENDPOINT_SEND_CLAR = 'http://game.coderunner.jp/sendClar'
ENDPOINT_ = ''
# ENDPOINT_PROFILE = 'TODO'
def enter():
p = {
'token': TOKEN
}
r = requests.get(ENDPOINT_ENTER, params=p)
return r.text
def info():
p = {
'token': TOKEN
}
r = requests.get(ENDPOINT_INFO, params=p)
return r.text
def room(rid):
p = {
'rid': rid,
'token': TOKEN
}
r = requests.get(ENDPOINT_ROOM, params=p)
return r.text
def myrank():
p = {
'token': TOKEN
}
r = requests.get(ENDPOINT_MYRANK, params=p)
return r.text
def main():
if len(sys.argv) > 1:
if sys.argv[1] == 'enter':
ret = enter()
elif sys.argv[1] == 'info':
ret = info()
elif sys.argv[1] == 'myrank':
ret = myrank()
elif sys.argv[1] == 'room':
ret = room(sys.argv[2])
print ret
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.