2009-08-25 18:04:42 -06:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
import game
|
|
|
|
|
2009-08-26 15:14:09 -06:00
|
|
|
class Roshambo(game.TurnBasedGame):
|
2009-08-25 18:04:42 -06:00
|
|
|
def setup(self):
|
2009-08-26 15:14:09 -06:00
|
|
|
self.moves = []
|
|
|
|
|
|
|
|
def calculate_moves(self):
|
|
|
|
moves = [m[1] for m in self.moves]
|
|
|
|
if moves[0] == moves[1]:
|
|
|
|
self.moves[0][0].write('tie')
|
|
|
|
self.moves[1][0].write('tie')
|
|
|
|
self.moves = []
|
|
|
|
elif moves in (('rock', 'scissors'),
|
|
|
|
('scissors', 'paper'),
|
|
|
|
('paper', 'rock')):
|
|
|
|
# First player wins
|
|
|
|
self.declare_winner(self.moves[0][0])
|
|
|
|
else:
|
|
|
|
self.declare_winner(self.moves[1][0])
|
2009-08-25 18:04:42 -06:00
|
|
|
|
|
|
|
def make_move(self, player, move):
|
2009-08-26 15:14:09 -06:00
|
|
|
self.moves.append((player, move))
|
|
|
|
self.end_turn(player)
|
|
|
|
|
|
|
|
def do_rock(self, player, args):
|
|
|
|
self.make_move(player, 'rock')
|
|
|
|
|
|
|
|
def do_scissors(self, player, args):
|
|
|
|
self.make_move(player, 'scissors')
|
|
|
|
|
|
|
|
def do_paper(self, player, args):
|
|
|
|
self.make_move(player, 'paper')
|
2009-08-25 18:04:42 -06:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
game.run(2, Roshambo, 5388, b'roshambo:::984233f357ecac03b3e38b9414cd262b')
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|