Skip to content

Instantly share code, notes, and snippets.

@segfault87
Last active September 18, 2018 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save segfault87/c6bd3572ca48ad970fcfb087362f774b to your computer and use it in GitHub Desktop.
Save segfault87/c6bd3572ca48ad970fcfb087362f774b to your computer and use it in GitHub Desktop.
파이콘 2018 상위 10 제출
import json
import random
import sys
def action(what):
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
def may_test_bot(damage, time_left):
return all(
[damage == 0, time_left < 2]
)
뒤_공간 = 3
대미지 = 0
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
given_damage = status['given_damage']
taken_damage = status['taken_damage']
match_records = status['match_records']
대미지 += given_damage + taken_damage
if distance == 0:
if may_test_bot(대미지, time_left):
action(random.choice(['punch', 'kick']))
else:
if 뒤_공간 > 0:
뒤_공간 -= 1
action('backward')
else:
action(random.choice(['punch', 'kick', 'crouch', 'jump', 'guard']))
elif distance == 1:
if may_test_bot(대미지, time_left):
뒤_공간 += 1
action('forward')
else:
action(random.choice(['punch', 'kick']))
elif distance > 1:
뒤_공간 += 1
action('forward')
if time_left == 0:
뒤_공간 = 0
대미지 = 0
import json
import sys
import random
def action(what):
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
given_damage = status['given_damage']
taken_damage = status['taken_damage']
match_records = status['match_records']
if health > opponent_health :
action(random.choice(['backward','punch', 'kick','crouch', 'jump', 'guard']))
elif distance == 1:
action(random.choice(['guard','backward','crouch','jump','punch','forward']))
elif distance > 0:
action(random.choice(['guard','backward','forward','forward','forward','forward']))
else:
if health > opponent_health :
action(random.choice(['backward','punch', 'kick','crouch', 'jump', 'guard']))
else:
action(random.choice(['punch', 'kick','crouch', 'jump', 'guard']))
import json
import random
import sys
def action(what):
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
prev_action = 'idle'
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
given_damage = status['given_damage']
taken_damage = status['taken_damage']
match_records = status['match_records']
if distance > 0:
if prev_action and prev_action == 'forward':
prev_action = 'guard'
action(prev_action)
else:
prev_action = 'forward'
action(prev_action)
else:
if prev_action in ('guard', 'forward'):
prev_action = random.choice(('punch', 'kick'))
action(prev_action)
else:
prev_action = 'guard'
action(prev_action)
import json
import sys
import random
def action(what):
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
given_damage = status['given_damage']
taken_damage = status['taken_damage']
match_records = status['match_records']
if distance >= 3:
action('forward')
#싸우는메타
elif distance == 0:
fight = ['punch', 'kick', 'guard']
action(random.choice(fight))
else:
ran =['forward','backward', 'kick', 'punch', 'guard']
action(random.choice(ran))
# 🍺 Nothing special!! 🍺
import json
import sys
my_action = None
def action(what):
# 🍺Remember my last action🍺
global my_action
my_action = what
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
def is_missed(opponent_action):
global my_action
if opponent_action == 'jump' and my_action == 'kick': return True
if opponent_action == 'crouch' and my_action == 'punch': return True
return False
def is_blocked(opponent_action):
global my_action
return (opponent_action == 'guard') and (my_action == 'kick' or my_action == 'punch')
def do_attack():
global my_action
if my_action == 'punch':
action('kick')
else:
action('punch')
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
# 🍺ㅌㅌㅌ🍺
if time_left < 7 and opponent_health < health:
action('backward')
continue
# 🍺ㄱㄱㄱ🍺
if time_left - 3 < (opponent_health - health):
if distance > 0:
action('forward')
continue
else:
do_attack()
continue
# 🍺통상🍺
if distance > 1:
action('forward')
continue
if is_missed(opponent_action) or is_blocked(opponent_action):
action('guard')
continue
do_attack()
import json
import sys
import random
pre_action = 'idle'
distance_1_count = 0
position = 0
def action(what):
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
given_damage = status['given_damage']
taken_damage = status['taken_damage']
match_records = status['match_records']
if health > opponent_health:
if distance == 0:
if position == -3:
# fight
if pre_action == 'guard':
if random.randrange(0,2) == 0:
pre_action = 'punch'
action('punch')
else:
pre_action = 'kick'
action('kick')
elif pre_action == 'kick':
pre_action = 'punch'
action('punch')
elif pre_action == 'punch':
pre_action = 'guard'
action('guard')
else:
pre_action = 'kick'
action('kick')
else:
position -= 1
pre_action = 'backward'
action('backward')
else:
if pre_action == 'kick':
pre_action = 'punch'
action('punch')
else:
pre_action = 'kick'
action('kick')
else:
if distance > 1:
position += 1
pre_action = 'forward'
action('forward')
elif distance == 1:
distance_1_count += 1
if distance_1_count> 2:
position += 1
pre_action = 'forward'
action('forward')
else:
if pre_action == 'kick':
pre_action = 'punch'
action('punch')
else:
pre_action = 'kick'
action('kick')
else:
# fight
if pre_action == 'guard':
if random.randrange(0,2) == 0:
pre_action = 'punch'
action('punch')
else:
pre_action = 'kick'
action('kick')
elif pre_action == 'kick':
pre_action = 'punch'
action('punch')
elif pre_action == 'punch':
pre_action = 'guard'
action('guard')
else:
pre_action = 'kick'
action('kick')
import json
import sys
import random
last_action = 'idle'
def action(what):
global last_action
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
last_action = what
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
available_backsteps = 3
def attack():
random_action = random.choice(['punch', 'kick'])
action(random_action)
def defence():
global available_backsteps
if available_backsteps > 0:
available_backsteps -= 1
action('backward')
else:
random_action = random.choice(['crouch', 'jump', 'guard'])
action(random_action)
accumulated_given_damage = 0
accumulated_taken_damage = 0
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
given_damage = status['given_damage']
taken_damage = status['taken_damage']
match_records = status['match_records']
accumulated_given_damage += given_damage
accumulated_taken_damage += taken_damage
"""
당연한 것만 정의 나중에는 랜덤으로
"""
attacks = ['punch', 'kick']
if distance >= 2:
action('forward')
available_backsteps += 1
elif distance == 1:
if accumulated_given_damage == 0 and accumulated_taken_damage == 0 and time_left < 5:
action('forward')
elif last_action == 'punch':
action('kick')
elif last_action == 'kick':
action('punch')
else:
attack()
# 방어에 성공했다면 공격
elif (taken_damage > 0 and last_action == 'guard') or \
(last_action == 'crouch' and opponent_action == 'punch') or \
(last_action == 'jump' and opponent_action == 'kick'):
attack()
# 공격에 실패했다면 도망 -> 회피
elif (last_action in attacks and given_damage == 0) or \
(opponent_action == 'crouch' and last_action == 'punch') or \
(opponent_action == 'jump' and last_action == 'kick'):
defence()
# 공격성에 따른 랜덤 액션
else:
aggressivity = health * 1.0 / (opponent_health + health)
random_action = random.choices([attack, defence], weights=[1 - aggressivity, aggressivity])[0]
random_action()
import random
import json
import sys
def action(what):
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
given_damage = status['given_damage']
taken_damage = status['taken_damage']
match_records = status['match_records']
# Circumvent test
if time_left < 3 and (opponent_action in ('None', 'idle') or given_damage == 0):
if distance > 0:
action('forward')
continue
action(['punch', 'kick'][time_left % 2])
continue
# Go forward iff it's 100% safe to do so
if distance >= 2:
action('forward')
continue
# Repeat alternating punch and kick
action(['punch', 'kick'][time_left % 2])
continue
import json
import sys
import random
def action(what):
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
def not_pre_action(actions):
return random.choice([x for x in actions if x != pre_action])
def next_action(status):
global position
if status['health'] > status['opponent_health']:
if status['distance'] > 0:
if status['distance'] > 1:
return 'forward'
return not_pre_action(['idle', 'punch', 'kick', 'crouch', 'jump', 'guard'])
else:
if position == -3:
return not_pre_action(['kick', 'punch', 'guard'])
position -= 1
return 'backward'
else:
if status['distance'] > 0:
position += 1
return 'forward'
else:
return not_pre_action(['kick', 'punch', 'guard'])
pre_action = None
position = 0
for status in read_status():
next = next_action(status)
action(next)
pre_action = next
import json
import sys
import random
def action(what):
if what not in ('idle', 'forward', 'backward', 'punch', 'kick',
'crouch', 'jump', 'guard'):
raise ValueError(f'Unknown action type: {what}')
sys.stdout.write(what + '\n')
sys.stdout.flush()
def read_status():
data = sys.stdin.readline()
while data:
yield json.loads(data)
data = sys.stdin.readline()
d = 0
ops = []
def _which_defense():
p = ops.count('punch')
k = ops.count('kick')
if p > k:
return 'crouch'
elif p < k:
return 'jump'
else:
return random.choice([
'crouch', 'jump', 'guard', 'guard'
])
def _which_attack():
c = ops.count('crouch')
j = ops.count('jump')
if c > j:
return 'kick'
elif j < c:
return 'punch'
else:
return random.choice([
'kick', 'punch'
])
for status in read_status():
distance = status['distance']
time_left = status['time_left']
health = status['health']
opponent_health = status['opponent_health']
opponent_action = status['opponent_action']
given_damage = status['given_damage']
taken_damage = status['taken_damage']
match_records = status['match_records']
ops.append(opponent_action)
if health <= opponent_health:
if time_left < 6:
if distance > 0:
d += 1; action('forward')
else:
action(_which_attack())
else:
if distance > 1:
d += 1; action('forward')
elif distance == 1:
action(_which_attack())
else:
if random.random() > 0.66:
action(_which_defense())
else:
action(_which_attack())
else:
if d > -3:
if distance == 1:
action(_which_attack())
elif distance > 1:
action('idle')
else:
d -= 1; action('backward')
else:
if distance > 1:
d += 1; action('forward')
elif distance == 1:
action(_which_attack())
else:
action(_which_defense())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment