-
Notifications
You must be signed in to change notification settings - Fork 2
/
testcase_5_mortgage.py
140 lines (99 loc) · 3.36 KB
/
testcase_5_mortgage.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import adjudicator
class Debug_Dice:
def __init__(self):
self.value_list = [[2,1]]
self.die_1 = None
self.die_2 = None
self.double = False
self.double_counter = 0
def roll(self,ignore=False):
if len(self.value_list)!=0:
[self.die_1,self.die_2] = self.value_list.pop()
self.double = self.die_1 == self.die_2
if not ignore:
self.double_counter += self.double
print('Roll a {die_1} and a {die_2}'.format(die_1=self.die_1, die_2=self.die_2))
class Agent_1:
def __init__(self, id):
self.id = id
def getBMSTDecision(self, state):
return None
def buyProperty(self, state):
return False
def auctionProperty(self, state):
return 180
def receiveState(self, state):
pass
class Agent_2:
def __init__(self, id):
self.id = id
self.PLAYER_TURN_INDEX = 0
self.PROPERTY_STATUS_INDEX = 1
self.PLAYER_POSITION_INDEX = 2
self.PLAYER_CASH_INDEX = 3
self.PHASE_NUMBER_INDEX = 4
self.PHASE_PAYLOAD_INDEX = 5
def getBMSTDecision(self, state):
payload = state[self.PHASE_PAYLOAD_INDEX]
if 'cash' in payload:
debt = payload['cash']
current_player = state[self.PLAYER_TURN_INDEX] % 2
playerCash = state[self.PLAYER_CASH_INDEX][current_player]
if playerCash < debt:
return ("M", [21])
return None
def buyProperty(self, state):
return False
def auctionProperty(self, state):
return 200
def receiveState(self, state):
pass
def compare_states(state1,state2):
if not isinstance(state1,type(state2)) or (len(state1)!=len(state2)):
print("Inconsistent type or length detected for First argument")
return false
else:
count = 0
if (state1[0] == state2[0]): count+=1
flag = True
for property,property2 in zip(state1[1],state2[1]):
if property != property2:
flag = False
if flag: count+=1
if (state1[2][0] == state2[2][0]) and (state1[2][1] == state2[2][1]): count+=1
if (state1[3][0] == state2[3][0]) and (state1[3][1] == state2[3][1]): count+=1
if (state1[4] == state2[4]): count+=1
if len(state1[5]) == len(state2[5]):
flag = True
for key,key2 in zip(state1[5],state2[5]):
if state1[5][key] != state2[5][key]:
flag = False
if flag: count+=1
if count == 6:
return True
else:
print( str(count)+"/"+str(len(state2))+" arguments are correct." )
return False
def testcase_5(Adjudicator,AgentOne,AgentTwo):
print("Test #5 Description:")
print("AgentTwo will fall on Income Tax(Position 4) and has to pay the bank $200.")
print("But, he only has $150. He mortgages Kentucky Avenue(Position 21) and gets $110.")
print("Thus, he would clear his debt and would be left with $60.")
input_state = [11, [ 0, 1, 0, 1, 0, 0, -1, 0, -2, -2, 1, 0, 0, 0, -1, 0, 0,
0, 1, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0], [3, 1], [580, 150], 4, {}]
output_state = [12, [ 0, 1, 0, 1, 0, 0, -1, 0, -2, -2, 1, 0, 0, 0, -7, 0, 0,
0, 1, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0], [3, 4], [580, 60], 5, {}]
no_of_turns = 12
adjudicator = Adjudicator(AgentOne,AgentTwo,input_state,Debug_Dice,no_of_turns)
adjudicator.runGame()
final_state = adjudicator.state
result = compare_states(final_state,output_state)
if result: print("Pass")
else:
print("Fail")
print("Received Output:")
print(final_state)
print("")
return result
#Execution
testcase_5(adjudicator.Adjudicator,Agent_1,Agent_2)