# Echo client program
import socket
import random
import time

HOST = 'localhost'    # The remote host

# to act as a client
PORT = 50018              # The server port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

# to act as a server
mybidderid = 0  # this is the only thing that distinguishes the clients 

moneyleft = 100 # should change over time
mywins = 0 # how many i have won
otherwins = 0 # how many others have one

# DO SOMETHING HERE
# you need to change this to do something much more clever
def determinebid(moneyleft, mywins, otherwins):
  	return int(50*random.random())

# APPLICATION
nummoves = 3
j = 0
while(1):
   print("Auction round is: ", j)
   bidflag = 1
   while(bidflag == 1):
	x = determinebid(moneyleft, mywins, otherwins)
  	s.send(str(mybidderid) + " " + str(x))
  	# print "Have sent data from ", str(mybidderid)
  	data = s.recv(1024)
  	x = data.split(" ")
  	# print "Have received response at ", str(mybidderid), " of: ", ' '.join(x)
	if(x[0] != "Not"):
		bidflag = 0
	else:
		time.sleep(2)

   resultflag = 1
   while(resultflag == 1):
  	s.send(str(mybidderid) + " " + str(int(50*random.random())))
  	# print "Have sent data from ", str(mybidderid)
  	data = s.recv(1024)
  	x = data.split(" ")
  	# print "Have received response at ", str(mybidderid), " of: ", ' '.join(x)
	if(x[0] != "Not"):
		resultflag = 0
  		print(' '.join(x))
		# DO SOMETHING HERE
		# update moneyleft, mywins, otherwins
	else:
		time.sleep(2)
   j+= 1


