Exemple #1
0
 def addRandomPlayer(self, avgNumIntervals,startingseed):
     self.randomseed = startingseed
     newplayer = Prefs.random(avgNumIntervals, self.randomseed)
     self.playerList.append(newplayer)    
     self.totalPlayers += 1
     self.randomseed += 1    
     return newplayer
Exemple #2
0
 def addPlayerRadomPrefs(self, avgNumIntervals):
     # create a player with id and random playerPref
     player = Player(self.totalPlayers, Prefs.random(avgNumIntervals))
     # add it to the list
     self.playerList.append(player)
     # increase the counter
     self.totalPlayers += 1
Exemple #3
0
import sys, os.path

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from prefs.Prefs import Prefs
from strom import StromquistKnives

if __name__ == '__main__':
    pass

f1 = sys.argv[1]
f2 = sys.argv[2]
f3 = sys.argv[3]

p1 = Prefs.fromFile(f1)
p2 = Prefs.fromFile(f2)
p3 = Prefs.fromFile(f3)

stromK = StromquistKnives(p1, p2, p3)
stromK.run()
Exemple #4
0
import sys, os.path
from time import time
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from prefs.Prefs import Prefs
from strom import StromquistKnives, StromquistP1Right, StromquistP1MidRight, StromquistAllRight, StromquistAllMidRight

if __name__ == '__main__':
    pass

p1 = Prefs.fromFile("../../data/ascending")
p2 = Prefs.fromFile("../../data/descending")
p3 = Prefs.fromFile("../../data/uniform")


def runOneTest(name, p1, p2, p3, type, resolution=0.001):
    dc = type(p1, p2, p3, False, resolution)
    result = dc.run()
    pi1, pi2, pi3 = result
    received_vals = [piece['winnerValue'] for piece in result]
    envy = checkForEnvy(result, resolution)
    return received_vals, envy


def checkForEnvy(pieces, resolution):
    received_vals = [piece['winnerValue'] for piece in pieces]
    total_envy = [0, 0, 0]

    for pnum in range(3):
        piece = pieces[pnum]
        piece_envy = [0, 0, 0]
Exemple #5
0
from prefs.Prefs import Prefs

if __name__ == '__main__':
    pass


def runOneTest(name,p1,p2,resolution=0.01):
    print("\n"+name)    
    dc = DivideAndChoose(p1, p2, resolution)
    result = dc.run()
    print("   Answer is " + str(result))
    pi1, pi2 = result
    print("   P1 got " + str(pi1) + " with value " + str(p1.valueOfPiece(pi1)))
    print("   P2 got " + str(pi2) + " with value " + str(p2.valueOfPiece(pi2)))
    
runOneTest("Files ascending and descending",Prefs.fromFile("../../data/ascending"), Prefs.fromFile("../../data/descending"))

for i in range(0,5):
    runOneTest("Random run " + str(i),Prefs.random(10), Prefs.random(10))
    
p1 = Prefs.random(100)
p2 = Prefs.random(100)

for r in range(0,5):
    resolution = 1.0/10**r
    runOneTest("Resolution " + str(resolution),p1,p2,resolution)

    
if len(sys.argv) == 3:
    f1 = sys.argv[1]
    f2 = sys.argv[2]
Exemple #6
0
import sys, os.path
from time import time
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from prefs.Prefs import Prefs
from strom import StromquistKnives, StromquistP1Right, StromquistP1MidRight, StromquistAllRight, StromquistAllMidRight

if __name__ == '__main__':
  pass

p1 = Prefs.fromFile("../../data/ascending")
p2 = Prefs.fromFile("../../data/descending")
p3 = Prefs.fromFile("../../data/uniform")

def runOneTest(name,p1,p2,p3, type, resolution=0.001):
    dc = type(p1, p2, p3, False, resolution)
    result = dc.run()
    pi1, pi2, pi3 = result
    received_vals = [piece['winnerValue'] for piece in result]
    envy =  checkForEnvy(result, resolution)
    return received_vals, envy


def checkForEnvy(pieces, resolution):
  received_vals = [piece['winnerValue'] for piece in pieces]
  total_envy = [0, 0, 0]

  for pnum in range(3):
    piece = pieces[pnum]
    piece_envy = [0, 0, 0]
    for k in range(3):
 def addRandomPlayer(self, avgNumIntervals):
     newplayer = Prefs.random(avgNumIntervals)
     self.playerList.append(newplayer)
     self.totalPlayers += 1
     return newplayer
 def addPlayerFromFile(self, filename):
     playerPref = Prefs.fromFile(filename)
     self.totalPlayers += 1
     self.playerList.append(playerPref)
     return playerPref
'''
This is the file Kevin will call from the web page.
It is listed in the algs file at the top level of the repo,
  saying that it takes 2 prefs file names as input
'''
import sys
import os
if __name__ == '__main__':
    pass
'''
Make sure Kevin's web page can get to the python packages
'''
sys.path.insert(0,os.path.abspath(os.path.join(os.path.dirname(__file__),os.path.pardir)))

from DivideAndChoose import DivideAndChoose
from prefs.Prefs import Prefs

'''
Kevin supplies the filenames to us, chosen from the web page
'''
f1 = sys.argv[1]
f2 = sys.argv[2]

'''
Now do what you want
'''
dc = DivideAndChoose(Prefs.fromFile(f1), Prefs.fromFile(f2))
pi1, pi2 = dc.run()
print ("answer is pi1 = " + str(pi1) + " and pi2 = " + str(pi2))
Exemple #10
0
import sys, os.path

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

from prefs.Prefs import Prefs
from strom import StromquistKnives

if __name__ == "__main__":
    pass


f1 = sys.argv[1]
f2 = sys.argv[2]
f3 = sys.argv[3]

p1 = Prefs.fromFile(f1)
p2 = Prefs.fromFile(f2)
p3 = Prefs.fromFile(f3)


stromK = StromquistKnives(p1, p2, p3)
stromK.run()