예제 #1
0
        static void Main(string[] args)
        {
            // Instantiate a new Fifo based space.
            ISpace ts = new SequentialSpace();

            // Insert the forks that the philosophers must share.
            ts.Put("FORK", 1);
            ts.Put("FORK", 2);
            ts.Put("FORK", 3);
            ts.Put("FORK", 4);
            ts.Put("FORK", 5);

            // Instantiate the philosopher agents.
            List <AgentBase> agents = new List <AgentBase>();

            agents.Add(new Philosopher("Alice", 1, 5, ts));
            agents.Add(new Philosopher("Charlie", 2, 5, ts));
            agents.Add(new Philosopher("Bob", 3, 5, ts));
            agents.Add(new Philosopher("Dave", 4, 5, ts));
            agents.Add(new Philosopher("Homer", 5, 5, ts));

            // Let the philosophers eat.
            agents.ForEach(a => a.Start());
            Console.Read();
        }
예제 #2
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please specify your name");
                return;
            }
            // Instantiate a new Fifobased tuple space.
            ISpace dtu = new SequentialSpace();

            // Insert a tuple with a message.
            dtu.Put("Hello student!");

            // Instantiate a new agent, assign the tuple space and start it.
            AgentBase student = new Student(args[0], dtu);

            student.Start();

            // Wait and retrieve the message from the agent.
            ITuple tuple = dtu.Get(typeof(string), typeof(string));

            // Print the contents to the console.
            Console.WriteLine(string.Format("{0}, you are attending course {1}", tuple[0], tuple[1]));
            Console.Read();
        }
예제 #3
0
        static void Main(string[] args)
        {
            string serverUrl = "tcp://" + ConnectionInfo.SERVER_ADDRESS + "/space?KEEP";

            Console.WriteLine($"Launching server at '{serverUrl}'");

            SpaceRepository repository = new SpaceRepository();

            repository.AddGate(serverUrl);
            SequentialSpace space = new SequentialSpace();

            repository.AddSpace(ConnectionInfo.SPACE_NAME, space);

            Connection.Space      = space;
            Connection.repository = repository;

            PlayerController newUserProtocol = new PlayerController();
            Thread           newUserThread   = new Thread(new ThreadStart(newUserProtocol.RunProtocol));

            newUserThread.Start();

            LobbyController lobbyController = new LobbyController(repository);

            lobbyController.Start();

            Console.WriteLine("Server started");
        }
예제 #4
0
 private void ReservePlayersToSpace(SequentialSpace space, int players_to_reserve)
 {
     space.Put("lobby_lock");
     for (int i = 0; i < players_to_reserve; i++)
     {
         space.Put("player", 0, "No user");
     }
 }
예제 #5
0
 public Airplane(SequentialSpace CTSpace, SequentialSpace rwSpace, SequentialSpace twtSpace, SequentialSpace twlSpace, string credentials) //SpaceRepository airportRepository)
 {
     //this.airport = airportRepository;
     this.controlTowerSpace = CTSpace;
     this.runwaySpace       = rwSpace;
     //this.runwayLockSpace = rwlSpace;
     this.taxiwayLandingSpace = twlSpace;
     this.taxiwayTakeoffSpace = twtSpace;
     this.credentials         = credentials;
 }
예제 #6
0
        static void Main(string[] args)
        {
            SequentialSpace inbox = new SequentialSpace();

            inbox.Put("Hello world!");
            ITuple tuple = inbox.Get(typeof(string));

            Console.WriteLine(tuple);
            Console.Read();
        }
예제 #7
0
        public ControlTower(SequentialSpace runways, SequentialSpace taxiways, SequentialSpace hangars, SequentialSpace airplanes)
        {
            this.runwaySpace   = runways;
            this.taxiwaySpace  = taxiways;
            this.hangarSpace   = hangars;
            this.airplaneSpace = airplanes;

            //this.repository.AddSpace("Runways", runways);
            //this.repository.AddSpace("Taxiways", taxiways);
            //this.repository.AddSpace("Hangars", hangars);
        }
예제 #8
0
        static void Main(string[] args)
        {
            ISpace ts = new SequentialSpace(new EntityFactory());

            TerminalInfo.Initialize(80, 24);
            Game pongGame = new Game(ts);

            pongGame.AddPlayer(new AIPlayer(1, "AI1", ts));
            pongGame.AddPlayer(new AIPlayer(2, "AI2", ts));
            pongGame.Run();
            Console.ReadKey();
            pongGame.Stop();
        }
예제 #9
0
        private void AddGameLobby()
        {
            space = new SequentialSpace();
            ReservePlayersToSpace(space, MAX_NUM_SUBSCRIBERS);

            space.Put("winner-lock");

            repository.AddSpace(spaceID, space);

            //Initialize streeming components
            clientScores    = new ClientScores(space);
            streemComponent = new StreemComponents(space);
        }
예제 #10
0
        public Airplane(SequentialSpace CTSpace, SequentialSpace rwSpace, SequentialSpace twSpace, string credentials, AirField airField, bool realisticMode, string windDirection) //SpaceRepository airportRepository)
        {
            //this.airport = airportRepository;
            this.controlTowerSpace = CTSpace;
            this.runwaySpace       = rwSpace;
            this.taxiwaySpace      = twSpace;
            this.credentials       = credentials;
            this.runwayGUILock     = credentials + "Runway" + "-lock";
            this.taxiwayGUILock    = credentials + "Taxiway" + "-lock";

            this.translator = new Controller.Translator(rwSpace, twSpace, airField);

            this.windDirection = windDirection;
            this.realisticmode = realisticMode;
        }
예제 #11
0
        static void Main(string[] args)
        {
            ISpace           ts     = new SequentialSpace();
            List <AgentBase> agents = new List <AgentBase>();

            // We create Alice and Bob as Producer/Consumer agents
            // The constructor of agents takes the name of the agent as argument
            agents.Add(new Producer("Alice", ts));
            agents.Add(new FoodConsumer("Bob", ts));
            agents.Add(new FoodConsumer("Charlie", ts));
            agents.Add(new DrugConsumer("Dave", ts));
            // We start the agents
            agents.ForEach(a => a.Start());
            Console.Read();
        }
예제 #12
0
        static void Main(string[] args)
        {
            // Instantiate a new Fifobased tuple space.
            ISpace dtu = new SequentialSpace();

            // Instantiate a new agent, assign the tuple space and start it.
            AgentBase userA = new User("A", dtu);
            AgentBase userB = new User("B", dtu);

            userA.Start();
            userB.Start();

            Console.WriteLine("Starting");
            dtu.Put(0);
        }
예제 #13
0
        static void Main(string[] args)
        {
            ISpace ts = new SequentialSpace(new EntityFactory());

            TerminalInfo.Initialize(80, 24);
            Game lifeforms = new Game(ts);

            lifeforms.AddLifeform(3, 100, 25);
            lifeforms.AddLifeform(5, 150, 25);
            lifeforms.AddLifeform(7, 90, 25);
            lifeforms.AddLifeform(11, 200, 25);
            lifeforms.AddLifeform(13, 130, 25);
            lifeforms.Run();
            Console.ReadKey();
            lifeforms.Stop();
        }
 public void CreateSequentialSpaceWithSequentialSpaceNameGeneratorTest()
 {
     using (var spaceRepo = new SpaceRepository())
     {
         string uri       = "tcp://127.0.0.1:5005";
         string testName  = NameHashingTool.GenerateUniqueSequentialSpaceName("ThisNameDoesNotActuallyMatter");
         ISpace testSpace = new SequentialSpace();
         spaceRepo.AddSpace(testName, testSpace);
         spaceRepo.AddGate(uri + "?CONN");
         var testElement = "This string is a test";
         testSpace.Put(testElement);
         testSpace.Get(testElement);
         Debug.Assert(!testSpace.GetAll().Any());
         // putting and getting the element should leave us with an empty space
     }
 }
예제 #15
0
        static void Main(string[] args)
        {
            // Instantiate a new Fifobased tuplespace.
            ISpace pingpongTable = new SequentialSpace();

            // Insert the ping.
            pingpongTable.Put("ping", 0);

            // Create two PingPong agents and start them.
            PingPong a1 = new PingPong("ping", "pong", pingpongTable);
            PingPong a2 = new PingPong("pong", "ping", pingpongTable);

            a1.Start();
            a2.Start();
            Console.Read();
        }
        public void CreateRemoteSpaceWithRemoteSpaceNameGeneratorTest()
        {
            using (var spaceRepo = new SpaceRepository())
            {
                string uri            = "tcp://127.0.0.1:5002";
                string testRemoteName = "ThisNameDoesNotActuallyMatter";
                string testSeqName    = NameHashingTool.GenerateUniqueSequentialSpaceName(testRemoteName);
                Console.WriteLine(testSeqName);
                var testSeqSpace = new SequentialSpace();
                spaceRepo.AddSpace(testSeqName, testSeqSpace);
                spaceRepo.AddGate(uri);

                var remoteHash = NameHashingTool.GenerateUniqueRemoteSpaceUri(uri, testRemoteName);
                Console.WriteLine(remoteHash);
                var testRemoteSpace = new RemoteSpace(remoteHash);
            }
        }
예제 #17
0
        // Create lobby (including tuple space), and send response
        // to player
        private void HandleCreationRequest(uint playerId, string playerName)
        {
            string lobbyId = GenerateLobbyId();

            string lobbyUrl = "tcp://" + ConnectionInfo.SERVER_ADDRESS + "/" + lobbyId + "?KEEP";

            var lobbySpace = new SequentialSpace();

            repository.AddSpace(lobbyId, lobbySpace);

            Lobby lobby = new Lobby(lobbySpace, lobbyId, playerId, playerName, lobbyUrl);

            lobbies.TryAdd(lobbyId, lobby);

            // Create lobby tuple
            Connection.Space.Put("existingLobby", lobbyId, playerName, lobbyUrl);
            lobby.Start();

            Console.WriteLine($"Lobby created: '{lobbyUrl}' (creator: {playerName})");

            // Returning space information to the global space so that users can connect to the space.
            Connection.Space.Put("lobbyCreationResponse", (int)playerId, playerName, lobbyUrl);
        }
 public HubTransformer(ISpace space, ISpace concealedSpace) : base(space)
 {
     ConcealedSpace = concealedSpace;
     PrivateSpace   = new SequentialSpace();
 }
예제 #19
0
 public Translator(SequentialSpace runways, SequentialSpace taxiways, AirField airField)
 {
     this.runwaySpace  = runways;
     this.taxiwaySpace = taxiways;
     this.airField     = airField;
 }
예제 #20
0
        public Airport(ITuple setup)//, int noOfHangers, int noOfControlTowers)
        {
            //this.airport = new SpaceRepository();
            this.runWaySpace       = new SequentialSpace();
            this.taxiWaySpace      = new SequentialSpace();
            this.controlTowerSpace = new SequentialSpace();
            this.airplaneSpace     = new SequentialSpace();
            //this.hanger = new SequentialSpace();
            //this.controlTower = new SequentialSpace();
            this.noOfRunways   = (int)setup[0];
            this.noOfTaxiways  = (int)setup[1];
            this.barrier       = (int)setup[2];
            this.noOfPlanes    = (int)setup[3];
            this.airField      = (AirField)setup[4];
            this.realisticMode = (bool)setup[5];
            this.windDirection = (string)setup[6];
            //this.noOfHangers = noOfHangers;
            //this.noOfControlTowers = noOfControlTowers;
            while (noOfRunways > 0 || noOfTaxiways > 0)//|| noOfHangers > 0)
            {
                if (noOfRunways > 0)
                {
                    if (noOfRunways == 2)
                    {
                        this.runWaySpace.Put("Runway Nr.", 0);
                    }

                    else
                    {
                        this.runWaySpace.Put("Runway Nr.", 90);
                    }

                    //this.runWaySpace.Put("Runway Nr. " + noOfRunways + " -lock");
                    noOfRunways--;
                }
                if (noOfTaxiways > 0)
                {
                    if (noOfTaxiways == 5)
                    {
                        this.taxiWaySpace.Put("Taxiway", "Alfa", barrier, barrier > 0);
                    }
                    else if (noOfTaxiways == 4)
                    {
                        this.taxiWaySpace.Put("Taxiway", "Beta", barrier, barrier > 0);
                    }
                    else if (noOfTaxiways == 3)
                    {
                        this.taxiWaySpace.Put("Taxiway", "Charlie", barrier, barrier > 0);
                    }
                    else if (noOfTaxiways == 2)
                    {
                        this.taxiWaySpace.Put("Taxiway", "Delta", barrier, barrier > 0);
                    }
                    else
                    {
                        this.taxiWaySpace.Put("Taxiway", "Epsilon", barrier, barrier > 0);
                    }
                    noOfTaxiways--;
                }

                /*if (noOfHangers > 0)
                 * {
                 *  this.hanger.Put("Hanger Nr.", noOfHangers);
                 *  noOfHangers--;
                 * }*/
                while (noOfControlTowers > 0)
                {
                    ControlTower controlTower = new ControlTower(runWaySpace, taxiWaySpace, hangerSpace, airplaneSpace);
                    if (controlTowerSpace != null)
                    {
                        this.controlTowerSpace.Put("Control Tower Nr.", noOfControlTowers, controlTower);
                        noOfControlTowers--;
                    }
                }
            }
            spawnAirplanes(airField);
            //this.airport.AddSpace("Runways", runWaySpace);
            //this.airport.AddSpace("Runway Locks", runWayLockSpace);
            //this.airport.AddSpace("Taxiways", taxiWaySpace);
            //this.airport.AddSpace("Hangers", hangerSpace);
            //this.airport.AddSpace("Control Towers", controlTowerSpace);
        }
예제 #21
0
 public ClientSession(ISpace space, string username)
 {
     Space      = space;
     LocalSpace = new SequentialSpace();
     Username   = username;
 }