-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnegotiatorUI.py
executable file
·89 lines (71 loc) · 2.8 KB
/
negotiatorUI.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
__author__ = 'Nick'
from negotiator_base import BaseNegotiator
from Tkinter import *
import matplotlib
matplotlib.use('TkAgg')
class negotiatorUI(BaseNegotiator):
def __init__(self):
##set up window here
self.window = Tk()
self.window.geometry("500x500+300+100")
self.window.title("Human Negotiator")
self.buttonlist = []
self.madeoffer = False
BaseNegotiator.__init__(self)
self.checkstate = []
self.currUtility = StringVar()
self.lastOffer = StringVar()
self.theirUtility = "0"
def initialize(self, preferences, iter_limit):
##add all items to window
self.preferences = preferences
latestOffer = Label(self.window, textvariable = self.lastOffer).pack()
currentUtility = Label(self.window, textvariable=self.currUtility).pack()
self.currUtility.set("Your Share's Utility: 0")
self.lastOffer.set("None")
i = 0
for x in self.preferences:
y = self.preferences.get(x,0)
print str(y)
buttonvar = IntVar()
self.buttonlist.append(buttonvar)
newCheckbutton = Checkbutton(self.window, text = str(x) + " = " + str(y),variable = self.buttonlist.__getitem__(i), command = self.updateItem).pack()
i+=1
sendButton = Button(self.window, text = "Send Offer",command = self.sendoffer).pack()
BaseNegotiator.initialize(self, preferences, iter_limit)
def updateItem(self):
self.checkCheckboxes()
def sendoffer(self):
self.madeoffer=True
self.window.quit()
def make_offer(self, offer):
self.madeoffer = False
self.offer = offer
self.lastOffer.set("They want " + str(self.offer) + " for an estimated " + self.theirUtility)
if offer is None:
self.offer = []
self.window.mainloop()
while(not self.madeoffer):
x = 1
return self.offer
def receive_utility(self, utility):
##write opponents utility from last offer
self.theirUtility = str(utility)
def receive_results(self, results):
BaseNegotiator.receive_results(self, results)
def utility(self):
x = BaseNegotiator.utility(self)
return x
def checkCheckboxes(self):
temp = 0
i = 0
self.offer = []
for x in self.preferences:
if(self.buttonlist[i].get()>0):
self.offer.append(x)
temp+=self.buttonlist[i].get()*self.preferences.get(x,0)
i+=1
string = str(temp)
print string
print str(self.offer)
self.currUtility.set("Your Share's Utility: " + string)