Skip to content

Instantly share code, notes, and snippets.

@VitamintK
Created February 6, 2015 04:01
Show Gist options
  • Save VitamintK/a56cf8de70a9f3572f0b to your computer and use it in GitHub Desktop.
Save VitamintK/a56cf8de70a9f3572f0b to your computer and use it in GitHub Desktop.
import YOUR_AI_FILENAME_HERE as AI
def get_sharpness(move_sequence: str):
def change_in_sharp(current_sharp: int, action: str):
if action == 'P' and current_sharp > 0:
return current_sharp - 1
elif action == 'S':
return current_sharp + 1
else:
return current_sharp
sharpness = 0
for i in move_sequence:
sharpness = change_in_sharp(sharpness, i)
return sharpness
def get_winner(player_move_string, opp_move_string, player_move, opp_move):
player_sharp = get_sharpness(player_move_string)
opp_sharp = get_sharpness(opp_move_string)
player_sword = player_sharp >= 5
opp_sword = opp_sharp >= 5
if player_move == 'P' and ((opp_move == 'S' and player_sharp > 0) or (player_sword and not (opp_sword and opp_move == 'P'))):
return True
human_move_string = ''
AI_move_string = ''
while True:
moves_string = AI_move_string + ',' + human_move_string
print('Human, your sharpness is {}'.format(get_sharpness(human_move_string)))
print('The AIs sharpness is {}'.format(get_sharpness(AI_move_string)))
human_move = input("Make a move (S/P/B): ").upper()
AI_move = AI.move(moves_string)
assert human_move in ('S', 'P', 'B'), 'Move should be one of the following characters: S, P, B'
assert AI_move in ('S', 'P', 'B'), 'Move should be one of the following characters: S, P, B'
print('human_move: {}'.format(human_move))
print('AI move: {}'.format(AI_move))
if get_winner(AI_move_string, human_move_string, AI_move, human_move):
print('AI WINS!!!! KILL ALL HUMANS')
break
if get_winner(human_move_string, AI_move_string, human_move, AI_move):
print('HUMAN WINS!!! SUCK IT, ROBOTS')
break
human_move_string += human_move
AI_move_string += AI_move
print()
@VitamintK
Copy link
Author

HOW TO USE:

  1. in the top line, replace YOUR_AI_FILENAME_HERE with the filename of your python module (without the .py).
  2. Your file needs to have a function named move() which takes as inputs the move-history-strings, and RETURNS the character of your move (S, P, or B).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment