Пример #1
0
def main():
    dimension = 15
    bounds = [0, 0, dimension - 1, dimension - 1]
    condition = [-5, -3, -1, 0, 1, 3, 5]
    minDistanceBetweenGrids = max(condition) + 1
    maxDistanceBetweenGrids = UpdateWorld.calculateMaxDistanceOfGrid(bounds) - minDistanceBetweenGrids
    block = 15
    initialWorld = UpdateWorld.InitialWorld(bounds)
    updateWorld = UpdateWorld.UpdateWorld(bounds, condition, minDistanceBetweenGrids, maxDistanceBetweenGrids)
    pg.init()
    screenWidth = 680
    screenHeight = 680
    screen = pg.display.set_mode((screenWidth, screenHeight))
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    textColorTuple = (255, 50, 50)
    softmaxBeta = 2.5
    episilonGreedy = 1
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT])

    picturePath = os.path.join(os.path.join(DIRNAME, '../..'), '/pictures/')
    resultsPath = os.path.join(os.path.join(DIRNAME, '../..'), '/results/')
    policyPath = os.path.join(os.path.join(DIRNAME, '../..'), 'machinePolicy/')
    humanController = HumanController(dimension)
    policyFile = open(policyPath + "noise0commitSnakeGoalGird15_policy.pkl", "rb")
    policy = pickle.load(policyFile)
    modelController = ModelController(policy, dimension, softmaxBeta, episilonGreedy)
    controller = modelController
    numberOfMachineRun = 20
    for i in range(16, numberOfMachineRun):
        experimentValues = co.OrderedDict()
        # experimentValues["name"] = input("Please enter your name:").capitalize()
        experimentValues["name"] = 'machineEpisilon' + str(episilonGreedy) + "_" + str(i)
        experimentValues["condition"] = 'None'
        writerPath = resultsPath + experimentValues["name"] + '.csv'
        writer = WriteDataFrameToCSV(writerPath)
        introductionImage = pg.image.load(picturePath + 'introduction.png')
        restImage = pg.image.load(picturePath + 'rest.png')
        finishImage = pg.image.load(picturePath + 'finish.png')
        introductionImage = pg.transform.scale(introductionImage, (screenWidth, screenHeight))
        finishImage = pg.transform.scale(finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4)))
        drawBackground = DrawBackground(screen, dimension, leaveEdgeSpace, backgroundColor, lineColor, lineWidth,
                                        textColorTuple)
        checkBoundary = CheckBoundary([0, dimension - 1], [0, dimension - 1])
        drawNewState = DrawNewState(screen, drawBackground, targetColor, playerColor, targetRadius, playerRadius)
        drawImage = DrawImage(screen)
        designValues = UpdateWorld.createDesignValues(condition * 3, block)
        restTrial = list(range(0, len(designValues), len(condition) * 15))
        trial = Trial(controller, drawNewState, checkBoundary)
        experiment = Experiment(trial, writer, experimentValues, initialWorld, updateWorld, drawImage, resultsPath,
                                minDistanceBetweenGrids, maxDistanceBetweenGrids, restImage, finishImage, restTrial)
        # drawImage(introductionImage)
        experiment(designValues)
Пример #2
0
    def constructButtons(self):
        posX = cfg.displaySize[0] / 2
        posY = cfg.displaySize[1] / 2
        pvp = Button(self.screen, "Person VS Person", (posX, posY - 150), 60)
        pvm = Button(self.screen, "Person VS Machine", (posX, posY - 50), 60)
        mvp = Button(self.screen, "Machine VS Person", (posX, posY + 50), 60)
        mvm = Button(self.screen, "Machine VS Machine", (posX, posY + 150), 60)

        pvp.playState = PlayState.PlayState(HumanController(),
                                            HumanController())
        pvm.playState = PlayState.PlayState(HumanController(),
                                            MinMaxController())
        mvp.playState = PlayState.PlayState(MinMaxController(),
                                            HumanController())
        mvm.playState = PlayState.PlayState(MinMaxController(),
                                            MinMaxController())

        self.buttons = [pvp, pvm, mvp, mvm]
Пример #3
0
    def constructButtons(self):
        posX = cfg.displaySize[0] / 2
        posY = cfg.displaySize[1] / 2
        pvp = Button(self.screen, "Person VS Person", (posX, posY - 150), 60)
        pvm = Button(self.screen, "Person VS Machine", (posX, posY - 50), 60)
        mvp = Button(self.screen, "Machine VS Person", (posX, posY + 50), 60)
        mvm = Button(self.screen, "Machine VS Machine", (posX, posY + 150), 60)

        human = HumanController()
        minmax = MinMaxController()
        pvp.setOnClickedCallback(target=self.buttonClickedCallback, args=(PlayState.PlayState(human, human),))
        pvm.setOnClickedCallback(target=self.buttonClickedCallback, args=(PlayState.PlayState(human, minmax),))
        mvp.setOnClickedCallback(target=self.buttonClickedCallback, args=(PlayState.PlayState(minmax, human),))
        mvm.setOnClickedCallback(target=self.buttonClickedCallback, args=(PlayState.PlayState(minmax, MinMaxController()),))

        self.buttons = [pvp, pvm, mvp, mvm]
Пример #4
0
def main():
    dimension = 21
    bounds = [0, 0, dimension - 1, dimension - 1]
    minDistanceBetweenGrids = 5
    condition = [-5, -3, -1, 0, 1, 3, 5]
    initialWorld = UpdateWorld.InitialWorld(bounds)
    pg.init()
    screenWidth = 720
    screenHeight = 720
    screen = pg.display.set_mode((screenWidth, screenHeight))
    gridSize = 21
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    stopwatchUnit = 10
    textColorTuple = (255, 50, 50)
    stopwatchEvent = pg.USEREVENT + 1
    pg.time.set_timer(stopwatchEvent, stopwatchUnit)
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT, stopwatchEvent])
    finishTime = 90000
    currentStopwatch = 32888
    score = 0
    drawBackground = DrawBackground(screen, gridSize, leaveEdgeSpace,
                                    backgroundColor, lineColor, lineWidth,
                                    textColorTuple)
    drawNewState = DrawNewState(screen, drawBackground, targetColor,
                                playerColor, targetRadius, playerRadius)
    humanController = HumanController(gridSize, stopwatchEvent, stopwatchUnit,
                                      drawNewState, finishTime)
    policy = pickle.load(open("SingleWolfTwoSheepsGrid15.pkl", "rb"))
    modelController = ModelController(policy, gridSize, stopwatchEvent,
                                      stopwatchUnit, drawNewState, finishTime)
    trial = Trial(modelController, drawNewState, stopwatchEvent, finishTime)
    bean1Grid, bean2Grid, playerGrid = initialWorld(minDistanceBetweenGrids)
    bean1Grid = (3, 13)
    bean2Grid = (5, 0)
    playerGrid = (0, 8)
    results = trial(bean1Grid, bean2Grid, playerGrid, score, currentStopwatch)
Пример #5
0
def main():
    dimension = 15
    minDistanceBetweenGrids = 5
    blockNumber = 3
    noiseCondition = list(permutations([1, 2, 0], 3))
    noiseCondition.append((1, 1, 1))
    picturePath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Pictures/'
    resultsPath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Results/'
    machinePolicyPath = os.path.abspath(os.path.join(
        os.getcwd(), os.pardir)) + '/machinePolicy/'
    bottom = [4, 6, 8]
    height = [6, 7, 8]
    direction = [0, 90, 180, 270]
    noiseDesignValues = UpdateWorld.createNoiseDesignValue(
        noiseCondition, blockNumber)
    shapeDesignValues = UpdateWorld.createShapeDesignValue(bottom, height)
    updateWorld = UpdateWorld.UpdateWorld(direction, dimension)
    pg.init()
    screenWidth = 600
    screenHeight = 600
    screen = pg.display.set_mode((screenWidth, screenHeight))
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    textColorTuple = (255, 50, 50)
    softmaxBeta = -1
    experimentValues = co.OrderedDict()
    for i in range(50):
        experimentValues["name"] = "maxModel" + str(i)
        # experimentValues["name"] = input("Please enter your name:").capitalize()
        writerPath = resultsPath + experimentValues["name"] + '.csv'
        writer = WriteDataFrameToCSV(writerPath)
        introductionImage = pg.image.load(picturePath + 'introduction.png')
        finishImage = pg.image.load(picturePath + 'finish.png')
        introductionImage = pg.transform.scale(introductionImage,
                                               (screenWidth, screenHeight))
        finishImage = pg.transform.scale(
            finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4)))
        drawBackground = DrawBackground(screen, dimension, leaveEdgeSpace,
                                        backgroundColor, lineColor, lineWidth,
                                        textColorTuple)
        drawText = DrawText(screen, drawBackground)
        drawNewState = DrawNewState(screen, drawBackground, targetColor,
                                    playerColor, targetRadius, playerRadius)
        drawImage = DrawImage(screen)
        policy = pickle.load(
            open(machinePolicyPath + "noise0.1WolfToTwoSheepGird15_policy.pkl",
                 "rb"))
        modelController = ModelController(policy, dimension, softmaxBeta)
        humanController = HumanController(dimension)
        checkBoundary = CheckBoundary([0, dimension - 1], [0, dimension - 1])
        controller = modelController
        normalNoise = NormalNoise(controller)
        awayFromTheGoalNoise = AwayFromTheGoalNoise(controller)
        normalTrial = NormalTrial(controller, drawNewState, drawText,
                                  normalNoise, checkBoundary)
        specialTrial = SpecialTrial(controller, drawNewState, drawText,
                                    awayFromTheGoalNoise, checkBoundary)
        experiment = Experiment(normalTrial, specialTrial, writer,
                                experimentValues, updateWorld, drawImage,
                                resultsPath, minDistanceBetweenGrids)
        # drawImage(introductionImage)
        experiment(noiseDesignValues, shapeDesignValues)
Пример #6
0
def main():
    dimension = 15
    bounds = [0, 0, dimension - 1, dimension - 1]
    condition = [-5, -3, -1, 0, 1, 3, 5]
    minDistanceBetweenGrids = max(condition) + 1
    maxDistanceBetweenGrids = UpdateWorld.calculateMaxDistanceOfGrid(
        bounds) - minDistanceBetweenGrids
    block = 1
    initialWorld = UpdateWorld.InitialWorld(bounds)
    updateWorld = UpdateWorld.UpdateWorld(bounds, condition,
                                          minDistanceBetweenGrids,
                                          maxDistanceBetweenGrids)
    pg.init()
    screenWidth = 680
    screenHeight = 680
    screen = pg.display.set_mode((screenWidth, screenHeight))
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    textColorTuple = (255, 50, 50)
    softmaxBeta = -1
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT])
    picturePath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Pictures/'
    resultsPath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Results/'
    policyPath = os.path.abspath(os.path.join(os.getcwd(),
                                              os.pardir)) + '/machinePolicy/'
    experimentValues = co.OrderedDict()
    experimentValues["name"] = input("Please enter your name:").capitalize()
    experimentValues["condition"] = 'None'
    writerPath = resultsPath + experimentValues["name"] + '.csv'
    writer = WriteDataFrameToCSV(writerPath)
    introductionImage = pg.image.load(picturePath + 'introduction.png')
    restImage = pg.image.load(picturePath + 'rest.png')
    finishImage = pg.image.load(picturePath + 'finish.png')
    introductionImage = pg.transform.scale(introductionImage,
                                           (screenWidth, screenHeight))
    finishImage = pg.transform.scale(
        finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4)))
    drawBackground = DrawBackground(screen, dimension, leaveEdgeSpace,
                                    backgroundColor, lineColor, lineWidth,
                                    textColorTuple)
    checkBoundary = CheckBoundary([0, dimension - 1], [0, dimension - 1])
    drawNewState = DrawNewState(screen, drawBackground, targetColor,
                                playerColor, targetRadius, playerRadius)
    drawImage = DrawImage(screen)
    humanController = HumanController(dimension)
    # policy = pickle.load(open(policyPath+"SingleWolfTwoSheepsGrid15.pkl","rb"))
    # modelController = ModelController(policy, dimension,softmaxBeta)
    designValues = UpdateWorld.createDesignValues(condition * 3, block)
    restTrial = list(range(0, len(designValues), len(condition) * 15))
    trial = Trial(humanController, drawNewState, checkBoundary)
    experiment = Experiment(trial, writer, experimentValues, initialWorld,
                            updateWorld, drawImage, resultsPath,
                            minDistanceBetweenGrids, maxDistanceBetweenGrids,
                            restImage, finishImage, restTrial)
    drawImage(introductionImage)
    experiment(designValues)
def main():
    gridSize = 15
    bounds = [1, 1, gridSize - 2, gridSize - 2]
    minDistanceBetweenGrids = 5
    condition = [-5, -3, -1, 0, 1, 3, 5]
    counter = [0] * len(condition)
    initialWorld = UpdateWorld.InitialWorld(bounds)
    updateWorld = UpdateWorld.UpdateWorld(bounds, condition, counter)
    pg.init()
    screenWidth = 680
    screenHeight = 680
    screen = pg.display.set_mode((screenWidth, screenHeight))
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    stopwatchUnit = 100
    finishTime = 1000 * 30
    block = 1
    textColorTuple = (255, 50, 50)
    stopwatchEvent = pg.USEREVENT + 1
    pg.time.set_timer(stopwatchEvent, stopwatchUnit)
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT, stopwatchEvent])
    picturePath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Pictures/'
    resultsPath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Results/'
    experimentValues = co.OrderedDict()
    experimentValues["name"] = input("Please enter your name:").capitalize()
    experimentValues["condition"] = 'None'
    writerPath = resultsPath + experimentValues["name"] + '.csv'
    writer = WriteDataFrameToCSV(writerPath)
    introductionImage = pg.image.load(picturePath + 'introduction.png')
    restImage = pg.image.load(picturePath + 'rest.png')
    finishImage = pg.image.load(picturePath + 'finish.png')
    introductionImage = pg.transform.scale(introductionImage,
                                           (screenWidth, screenHeight))
    finishImage = pg.transform.scale(
        finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4)))
    drawBackground = DrawBackground(screen, gridSize, leaveEdgeSpace,
                                    backgroundColor, lineColor, lineWidth,
                                    textColorTuple)
    drawNewState = DrawNewState(screen, drawBackground, targetColor,
                                playerColor, targetRadius, playerRadius)
    drawImage = DrawImage(screen)
    humanController = HumanController(gridSize, stopwatchEvent, stopwatchUnit,
                                      drawNewState, finishTime)
    trial = Trial(humanController, drawNewState, stopwatchEvent, finishTime)
    experiment = Experiment(trial, writer, experimentValues, initialWorld,
                            updateWorld, drawImage, resultsPath,
                            minDistanceBetweenGrids)
    giveExperimentFeedback = GiveExperimentFeedback(screen, textColorTuple,
                                                    screenWidth, screenHeight)
    drawImage(introductionImage)
    score = [0] * block
    for i in range(block):
        score[i] = experiment(finishTime)
        giveExperimentFeedback(i, score)
        if i == block - 1:
            drawImage(finishImage)
        else:
            drawImage(restImage)

    participantsScore = np.sum(np.array(score))
    print(participantsScore)