-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflexAgent2.py
56 lines (45 loc) · 1.98 KB
/
reflexAgent2.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
from randomClient import RandomClient
from featureExtractor import *
import random, argparse, sys
from PyQt5.QtCore import QCoreApplication
class reflexAgent(RandomClient):
def __init__(self, client_id = None, serverPort = 0,
serverAddress = 'localhost', name = 'Noname', client_type = 'PLAYER'):
super().__init__(client_id, serverPort, serverAddress, name, client_type)
def chooseTile(self, actions):
if len(actions) == 1: # covers the case that the only tile is 'Nothing'
return actions[0]
outcomes = placementOutcome(self.state, actions)
for k,v in outcomes:
if v == 'found':
return k
return random.choice(actions)
def chooseNewCompany(self, actions): return random.choice(actions)
def chooseSurvivor(self, actions): return random.choice(actions)
def chooseLiquidate(self, actions): return random.choice(actions)
def chooseStock(self, actions):
actions.remove('Done')
if len(actions) == 0:
return 'Done'
if len(actions) == 1:
return actions[0]
choices = list()
for company in actions:
bonuses = getBonus(self.state, company)
if bonuses[0]['Player'] == bonuses[1]['Player'] and bonuses[0]['Player'] != self.name:
choices.append(company)
elif self.name != bonuses[0]['Player'] and self.name != bonuses[1]['Player']:
choices.append(company)
if len(choices):
return random.choice(choices)
else:
return random.choice(actions)
def chooseEndGame(self, actions): return "Yes"
if __name__ == '__main__':
app = QCoreApplication(sys.argv)
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--serverPort', type = int)
parser.add_argument('-n', '--playerName', type = str)
args = parser.parse_args()
a = reflexAgent(name = args.playerName, serverPort = args.serverPort)
app.exec_()