示例#1
0
def main():
    battlesimulator = Master()
    battlesimulator.introMessage()
    setupPlayers = SetupPlayers()
    setupPlayers.askPlayer()
    battlesimulator.displayStats(Warrior(1, 2, 3), Warrior(4, 5, 6))
    warriorSet = WarriorSet(Warrior(1, 2, 3), Warrior(4, 5, 6))
    warriorSet.printWarriors()
    simulation = Simulation()
    simulation.setWarriors(Warrior(1, 2, 3), Warrior(4, 5, 6))
    simulation.run()
示例#2
0
class Painter(Frame):
    total = 1
    mas = Master.Master()
    scaling = 10.0
    intersection_Size = 4




### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### 
### ### ### ### ### ### ### ### ### ### ### ### ### ##### #
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### INITIALIZATION ### ### ### 
### ### ### ### ### ### ### ### ### ### ### ### ### ### ##### #
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### 
### ### ### ### ### ### ### ### ### ### ### ### ### ##### #


    def __init__(self, master=None):
        self.initializeFrame(master)
        self.initializeMap()
        self.after(10, self.update)


    def initializeFrame(self, master):
        Frame.__init__(self, master)
        Pack.config(self)
        self.createWidgets()

    def initializeMap(self):
        self.mas.printState()
        # Draw the intersections and streets
        for inter in self.mas.m.intersections:
            self.drawIntersection(inter, self.scaling * self.mas.m.intersections[inter][0], self.scaling * self.mas.m.intersections[inter][1])
        for street in self.mas.m.streets:
            self.drawStreet(street)
        for car in self.mas.cars:
            self.drawCar(car)



 ##############################################
 ###            stepping function           ###
 ##############################################

    def update(self, *args):

        # Let the Master class do a time step
        self.mas.run(self.total)
        self.total += 1
        self.mas.printCars()

        for car in self.mas.cars:
            if car.needsUpdate:
                self.updateCar(car)
                car.needsUpdate = False
        self.after(70, self.update)


    def updateCar(self, car):
        dx = self.getDX(car)
        dy = self.getDY(car)
        self.draw.move(car.name, dx, dy)
    
    def drawIntersection(self, label, x, y):
        self.draw.create_rectangle(x-self.intersection_Size, y-self.intersection_Size, x+self.intersection_Size  ,y+self.intersection_Size ,tags=label, fill="blue")

    def drawStreet(self, street):
        x0 = self.mas.m.intersections[street[0]][0] * self.scaling
        y0 = self.mas.m.intersections[street[0]][1] * self.scaling
        x1 = self.mas.m.intersections[street[1]][0] * self.scaling
        y1 = self.mas.m.intersections[street[1]][1] * self.scaling
        #self.draw.create_rectangle(x0-1, y0-1, x1+1, y1)
        self.draw.create_line(x0, y0, x1, y1, fill="red",)

    def drawCar(self, car):
        x = self.getXY(car.curPos)[0]
        y = self.getXY(car.curPos)[1]
        self.draw.create_rectangle(x - 3, y - 3, x + 3, y + 3, tags=car.name, fill="green")


    def getXY(self, carPos):
        streetID = carPos[0]
        street = self.mas.m.streets[streetID]
        length = float(street[2])
        x0 = self.mas.m.intersections[street[0]][0] * self.scaling
        y0 = self.mas.m.intersections[street[0]][1] * self.scaling
        x1 = self.mas.m.intersections[street[1]][0] * self.scaling
        y1 = self.mas.m.intersections[street[1]][1] * self.scaling
        direction = [x1 - x0, y1 - y0]
        progress = float(carPos[1])
        return [x0 + progress/length * direction[0], y0 + progress/length * direction[1]] 

    def getDX(self, car):
        return self.getXY(car.curPos)[0] - self.getXY(car.oldPos)[0]

    def getDY(self, car):
        return self.getXY(car.curPos)[1] - self.getXY(car.oldPos)[1]
        

    def createWidgets(self):
        self.QUIT = Button(self, text='QUIT', foreground='red', command=self.quit)
        self.QUIT.pack(side=BOTTOM, fill=BOTH)
        self.draw = Canvas(self, width="10i", height="10i")
        #self.speed = Scale(self, orient=HORIZONTAL, from_=-100, to=100)
        #self.speed.pack(side=BOTTOM, fill=X)

        # all of these work..
        #self.draw.create_rectangle(0, 0, 10, 10, tags="thing", fill="blue")
        self.draw.pack(side=LEFT)
示例#3
0
from Master import *
from Worker import *
import random
import sys
import time
"""
Main of the implementation 
execute the Implementation.
"""

# create a Transaction with parameter

if __name__ == '__main__':
    master = Master(name="Master")
    master.start()  # start the Master Thread
    senders_receivers = [
        "Marc", "Luc", "Antoine", "Mathieu", "Jean", "Patrick", "Stephane",
        "Junior"
    ]  # list of Person to execute Transactions request
    maxAmount = sys.maxsize  # initial Amount to the biggest interger in the system
    workers = []  # workers initialisations
    failedWorkers = []  # failed or malicious Workers
    workerNumber = 5  # numbers of Workers

    for i in range(1, workerNumber + 1):
        workers.append(StartWorker(name=f"Worker {i}"))
        master.addWorker(workers[i - 1])  # Present Workers to the Master

    for i in range(100):
        indexSender = random.randint(0,
                                     len(senders_receivers) -
示例#4
0
from mpi4py import MPI
import time
from Worker import *
from Master import *
from IO import *
from graph import *

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()

if rank == size - 1:  # master process
    master = Master(rank, size - 1, comm)
    master.Run()
else:
    worker = Worker("../graph/large.graph", rank, size - 1, comm)
    worker.Local_Graph()
    worker.Local_Step()
示例#5
0
#!/usr/bin/env python

from Master import *

master = Master()

master.createTable([{
    'key1': 'varchar(256)'
}, {
    'key2': 'int'
}, {
    'key3': 'varchar(1)'
}, {
    'key4': 'int'
}, {
    'res': 'int'
}])

params = [['a', 'b', 'c', 'd'], [1, 2, 3, 4], ['x', 'y', 'z'],
          [10, 20, 30, 40]]
master.setInputParams(params)
master.start()
示例#6
0
import Master
import Gameplay

master = Master.Master()
gameplay = Gameplay.Gameplay()

master.setGameplay(gameplay)

master.onStart()

print("This line will be printed.")
示例#7
0
class Controller:
    """
    The Controller is the connection which is made between a View and a Model, as expected in MVC-modeled software.
    The View is specified globally within the controller, as is the Master
    """
    view = None
    master = Master()

    def __init__(self):
        """
        The __init__ method initialises a View, as the controller must be given as argument to deal with user input.
        """
        self.view = GuiView(self)
        return

    def main(self, command):
        # Todo: Split
        """
        The main method is a method originally used as basis for a TUI, but is still used by the GUI for historic
        reasons. This method arranges Model changes accordingly based on user input in the View. Relatively new changes
        are not dealt with through this method, but separate smaller methods.

        This method should be splitted up in the future.

        E.g.
        > Controller.main('sweep 0 0 10 1')
        > None

        :param command: This is the command (as string) that is given to the method and describes the user input in a
        way that the Controller can forward it to the Model.
        :return: None
        """
        command = command.split(" ")
        if command[0] == 'openFile':
            print('hello2')
            if self.master.open_file(command[1]):
                print('File %s opened' % command[1])
            else:
                print('Filename unknown, failed opening...')
        elif command[0] == 'parameters':
            parameters = self.master.get_parameters()
            interactive = self.master.get_interactive()
            bs = self.master.get_bs()
            # print(str(parameters) + '\n\n')
            # print(str(interactive) + '\n\n')
            # print(bs)
            return parameters, interactive, bs
        elif command[0] == 'sweep':
            self.master.add_sweep(int(command[1]), int(command[2]), int(command[3]), int(command[4]))
            # sweeps.append([command[1], command[2], command[3], command[4]])
        elif command[0] == 'execute':
            return self.master.execute()
        elif command[0] == 'show':
            self.master.close_file()
        elif command[0] == 'exit':
            self.master.close_file()

    def get_sweeps(self):
        """
        Returns all sweeps that are stored in the model.
        :return: List of all currently stored sweeps.

        E.g.
        > Controller.get_sweeps()
        > [[0, 0, 10, 1], [1, 0, 20, 2]]
        """
        return self.master.get_sweeps()

    def quit(self):
        # Todo: Work out.
        """
        Called when the program is exited (both forced and unforced). Exits python.
        :return: quit(0)

        E.g.
        > Controller.quit()
        > quit()
        """
        print('Graceful exit!')
        quit(0)

    def simulate(self, query):
        """
        Used for simulating an amount of runs, considering parameter query.
        :param amount: The amount of runs that should be carried out over the UPPAAL-model stored in the Model.
        :param query: The UPPAAL-parameter that should be considered.
        :return: A list of traces of every run taken.

        E.g.
        > simulate(2, 'cost')
        > [ [ (0,0), (1,1), (2,2) ], [ (0,0), (1,2), (2,2) ] ]
        """
        return self.master.simulate(query)
示例#8
0
#########################################################################
    RPipeMstr is the core master process of RenderPipe. 
    Copyright (C) 2011 Hadi Saraf

    RPipeMstr is part of RenderPipe.

    RenderPipe is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#########################################################################
""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """"""

__version__ = 1.1

import Master

if "__main__" == __name__:
    print(
        "RenderPipe 1.1, master application, built May 08 2011.\nCopyright (C) 2011 Hadi Saraf.\n\n"
    )
    Master.Master()  # runs RPipeMstr
示例#9
0
import socket
import sys
from Master import *

# prompt user to enter secret key file
keyfile = input("Input secret key file: ")  #"fakeSecretKey.txt"

# create server socket
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# create master (usernumber 1)
mast = Master(keyfile, 1)
print("")

# bind server to localhost and port 8080, and listen for 1 connection
serv.bind(('0.0.0.0', 8080))
serv.listen(1)

while True:
    # accept connections from outside
    (conn, addr) = serv.accept()
    print("")
    print("Sending a session key status request to outstation...")
    messageOut = str(mast.sendStatusRequest())

    while True:

        # send message to client
        conn.send(messageOut.encode())

        # read data sent from client