-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.py
57 lines (47 loc) · 2.58 KB
/
agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from actions import Action
from cards import Cards
from exceptions import IllegalActionException
class AgentInterface(type):
def __new__(metaclass, name, bases, attrs):
expected_methods = {'new_round':2, 'see':3, 'play_card':2}
for method in expected_methods:
if method not in attrs:
raise TypeError('method %s missing from AgentInterface class' % method)
if attrs[method].__code__.co_argcount != expected_methods[method]:
raise TypeError('method %s requires exactly %d arguments (self inclusive)' %(method, expected_methods[method]))
return super().__new__(metaclass, name, bases, attrs)
def __call__(self, *args, **kwargs):
cls = type.__call__(self, *args, **kwargs)
for func in dir(type(self)):
if func[:2] == '__':
continue
setattr(cls, func, getattr(self, func))
return cls
def play_guard(self, player:int, target:int, guess:Cards) ->Action:
print('player: {0}, target: {1}, guess: {2}'.format(player, target, guess))
if(target == -1): raise IllegalActionException('Target myst be specified')
if(player == target): raise IllegalActionException('Player cannot target themself')
if(guess == None): raise IllegalActionException('Player must guess a card')
if(guess == Cards.GUARD): raise IllegalActionException('Player cannot guess a guard')
return Action(Cards.GUARD, player, target, guess)
def play_priest(self, player:int, target:int) ->Action:
if(target == -1): raise IllegalActionException('Target must be specified')
if(player == target): raise IllegalActionException('Player cannot target themself')
return Action(Cards.PRIEST, player, target, None)
def play_baron(self, player:int, target:int) ->Action:
if(target == -1): raise IllegalActionException('Target must be specified')
if(player == target): raise IllegalActionException('Player cannot target themself')
return Action(Cards.BARON, player, target, None)
def play_handmaid(self, player:int) ->Action:
return Action(Cards.HANDMAID, player, -1, None)
def play_prince(self, player:int, target:int) ->Action:
if(target == -1): raise IllegalActionException('Target must be specified')
return Action(Cards.PRINCE, player, target, None)
def play_king(self, player:int, target:int) ->Action:
if(target == -1): raise IllegalActionException('Target must be specified')
if(player == target): raise IllegalActionException('Player cannot target themself')
return Action(Cards.KING, player, target, None)
def play_countess(self, player:int) ->Action:
return Action(Cards.COUNTESS, player, -1, None)
def play_princess(self, player:int) ->Action:
return Action(Cards.PRINCESS, player, -1, None)