Examples of MessageMove


Examples of cz.matfyz.aai.fantom.message.MessageMove

   
    ActorMove[] moves = new ActorMove[] {
        new ActorMove(fantomas, n2, null),
        new ActorMove(joker, n1, null)
    };
    g.placeActors(new MessageMove(moves));
    moves = new ActorMove[] {
        new ActorMove(poirot, n4, null),
        new ActorMove(batman, n3, null),
        new ActorMove(japp, n5, null),
    };
    g.placeActors(new MessageMove(moves));
   
    assertSame(n2, fantomas.getCurrentPosition());
    assertSame(n1, joker.getCurrentPosition());
    assertSame(n4, poirot.getCurrentPosition());
    assertSame(n3, batman.getCurrentPosition());
    assertSame(n5, japp.getCurrentPosition());
   
    moves = new ActorMove[] {
        new ActorMove(poirot, n3, tram),
        new ActorMove(batman, n2, bus),
        new ActorMove(japp, n6, tram),
    };
    try {
      g.moveActors(g.getActors(ClientType.DETECTIVE), new MessageMove(moves));
      fail("Message validation failed - immobile detective did move");
    }
    catch(ProtocolException e) {
    }
  }
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

    for(int i = 0; i < actors.size(); i++) {
      assertEquals(actors.get(i), actorsRO.get(i));
      assertNotSame(actors.get(i), actorsRO.get(i));
    }
   
    g.placeActors(new MessageMove(new ActorMove[] {
        new ActorMove(g.getActor("Fantomas"), g.getNode("1"), null),
        new ActorMove(g.getActor("Joker"), g.getNode("2"), null),
    }));
   
    actors = g.getActors();
    actorsRO = gr.getActors();
    assertEquals(actors.size(), actorsRO.size());
    for(int i = 0; i < actors.size(); i++) {
      assertEquals(actors.get(i), actorsRO.get(i));
      assertNotSame(actors.get(i), actorsRO.get(i));
    }
   
    g.placeActors(new MessageMove(new ActorMove[] {
        new ActorMove(g.getActor("Poirot"), g.getNode("3"), null),
        new ActorMove(g.getActor("Batman"), g.getNode("4"), null),
    }));
  }
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

    Message msg = detectiveClient.receiveMessage(graph);
    if(!(msg instanceof MessageMove))
      throw new ProtocolException("'move' message was expected from the detective client", detectiveClient);
    logger.debug("Message received");
   
    MessageMove detectivePlacements = (MessageMove) msg;
    try {
      logger.trace("Placing detectives on the graph");
      graph.verifyActorPlacement(detectivePlacements, detectiveClient);
      graph.placeActors(detectivePlacements);
      logActorPlacement(detectiveClient, detectivePlacements);
      logger.trace("Detectives were placed");
    }
    catch(ClientException e) {
      e.setClient(detectiveClient);
      throw e;
    }

    // Inform the phantom about the initial placement of the detectives.
    logger.debug("Sending information about detective placement to the phantom");
    msg = new MessageUpdate(graph, detectivePlacements.getMoves(), null);
    phantomClient.sendMessage(msg);
    logger.trace("Message was sent");

    // Place the phantom.
    logger.debug("Receiving actor placement from the phantom");
    msg = phantomClient.receiveMessage(graph);
    if(!(msg instanceof MessageMove))
      throw new ProtocolException("'move' message was expected from the detective client", phantomClient);
    logger.trace("Message received");
   
    MessageMove phantomPlacement = (MessageMove) msg;
    try {
      logger.debug("Placing phantoms on the graph");
      graph.verifyActorPlacement(phantomPlacement, phantomClient);
      graph.placeActors(phantomPlacement);
      logActorPlacement(phantomClient, phantomPlacement);
      logger.trace("Phantoms were placed");
    }
    catch(ClientException e) {
      e.setClient(phantomClient);
      throw e;
    }

    processCapturedPhantoms(phantoms);
    if(phantoms.isEmpty()) {
      logger.info("All phantoms were captured, detectives won the game");
      return new MessageUpdate(graph, phantomPlacement.getMoves(), ClientType.DETECTIVE);
    }

    logger.debug("Letting the phantom start.");
    msg = new MessageUpdate(graph, new ActorMove[0], null);
    phantomClient.sendMessage(msg);
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

    logger.debug("Reading movement information from the phantom");
    Message msg = phantomClient.receiveMessage(graph);
    if(!(msg instanceof MessageMove))
      throw new ProtocolException("'move' message was expected from the detective client", phantomClient);
    logger.trace("Movement information from the phantom was received");
    MessageMove phantomMove = (MessageMove) msg;
    Collection<Actor> immobilePhantoms = null;
    try {
      logActorMovement(phantomClient, phantomMove);
      logger.debug("Updating actor positions in the graph");
      immobilePhantoms = graph.moveActors(phantoms, phantomMove);
      logger.trace("Actor positions were updated");
    }
    catch(ProtocolException e) {
      e.setClient(phantomClient);
      throw e;
    }
   
    // Mark all phantoms captured in this turn as captured, and remove them from the
    // list of active phantoms.
    logger.debug("Processing captured phantoms");
    processCapturedPhantoms(phantoms);
   
    // Inform the detectives.
    logger.debug("Sending detectives information about the moves of the phantom");
    MessageMoveBase.ActorMove[] pams = phantomMove.getMoves();
    if(!graph.getPhantomReveals().contains(round)) {
      // Hide the target.
      MessageMoveBase.ActorMove[] hpams = new MessageMoveBase.ActorMove[pams.length];
      for(int i = 0; i < pams.length; i++) {
        hpams[i] = new MessageMoveBase.ActorMove(pams[i].getActor(), null, pams[i].getTransportType());
      }
      pams = hpams;
    } else {
      if(immobilePhantoms.size() > 0) {
        // There are immobile phantoms. We need to add them to the message to reveal
        // their position.
        MessageMoveBase.ActorMove[] moves = new MessageMoveBase.ActorMove[pams.length + immobilePhantoms.size()];
        int pos = 0;
        for(int i = 0; i < pams.length; i++) {
          moves[pos++] = pams[i];
        }
        for(Actor phantom : immobilePhantoms) {
          moves[pos++] = new ActorMove(phantom, phantom.getCurrentPosition(), null);
        }
        pams = moves;
      }
    }
    if(phantoms.isEmpty()) {
      return new MessageUpdate(graph, pams, ClientType.DETECTIVE);
    }
    msg = new MessageUpdate(graph, pams, null);
    detectiveClient.sendMessage(msg);
    logger.trace("Message was sent");

    // Get the moves of detectives.
    logger.debug("Reading movement information from detectives");
    msg = detectiveClient.receiveMessage(graph);
    if(!(msg instanceof MessageMove))
      throw new ProtocolException("'move' message was expected from the detective client", detectiveClient);
    logger.trace("Movement information from the phantom was received");
    MessageMove detectiveMoves = (MessageMove) msg;
    try {
      logActorMovement(detectiveClient, detectiveMoves);
      logger.debug("Updating actor positions in the graph");
      graph.moveActors(detectives, detectiveMoves);
      logger.trace("Actor positions were updated");
    }
    catch(ProtocolException e) {
      e.setClient(detectiveClient);
      throw e;
    }
   
    // First process phantoms captured in the last move...
    logger.debug("Processing captured phantoms");
    processCapturedPhantoms(phantoms);
    if(phantoms.isEmpty()) {
      //return ClientType.DETECTIVE;
      return new MessageUpdate(graph, detectiveMoves.getMoves(), ClientType.DETECTIVE);
    }

    logger.debug("Distributing tickets used by detectives to phantoms");
    for(MessageMove.ActorMove m : detectiveMoves.getMoves()) {
      TransportType transport = m.getTransportType();

      if(transport.isUsedByPhantom()) {
        int lucky = rnd.nextInt(phantoms.size()); //TODO: With multiple phantoms, how should the tickets be distributed?
        Actor luckyActor = phantoms.get(lucky);
        logger.info(String.format("Phantom %s gets one ticket for transport %s", luckyActor.getId(), transport.getName()));
        phantoms.get(lucky).addTicket(transport);
      }
    }

    // Inform the phantom.
    logger.debug("Sending phantom information about movement of the detectives");
    ClientType winner = null;
    // If this is the last round, the phantom escaped and won the game
    if(round == graph.getGameLength()) {
      logger.info("Detectives did not catch the phantoms, phantoms won the game");
      winner = ClientType.PHANTOM;
      return new MessageUpdate(graph, detectiveMoves.getMoves(), winner);
    }
   
    MessageUpdate detectiveUpdate = new MessageUpdate(graph, detectiveMoves.getMoves(), winner);
    phantomClient.sendMessage(detectiveUpdate);
    logger.trace("Message was sent");

    logger.debug("Nobody won the current round");
    return null;
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

   
    ActorMove[] moves = new ActorMove[] {
      new ActorMove(fantomas, n1, null),
      new ActorMove(joker, n2, null)
    };
    MessageMove msg = new MessageMove(moves);
   
    // First try to verify it as a message from the phantom client.
    // This should succeed, as the message contains a correct placement
    // of the phantoms.
    g.verifyActorPlacement(msg, phantomClient);
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

   
    // Try a message, where a phantom actor is missing
    ActorMove[] moves = new ActorMove[] {
        new ActorMove(fantomas, n1, null)
    };
    MessageMove msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, phantomClient);
      fail("Message validation failed - not all actors were placed");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where one actor is placed multiple times
    moves = new ActorMove[] {
        new ActorMove(fantomas, n1, null),
        new ActorMove(joker, n2, null),
        new ActorMove(fantomas, n3, null)
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, phantomClient);
      fail("Message validation failed - an actor was placed multiple times");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where the transport type is specified for some
    // of the actors
    moves = new ActorMove[] {
        new ActorMove(fantomas, n1, tram),
        new ActorMove(joker, n2, null)
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, phantomClient);
      fail("Message validation failed - transport type was specified for an actor");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where the target node is missing for some of
    // the actors.
    moves = new ActorMove[] {
        new ActorMove(fantomas, null, tram),
        new ActorMove(joker, n2, null),
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, phantomClient);
      fail("Message validation failed - target node was not specified for an actor");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where a detective actor is placed
    moves = new ActorMove[] {
        new ActorMove(fantomas, n1, null),
        new ActorMove(joker, n2, null),
        new ActorMove(batman, n3, null)
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, phantomClient);
      fail("Message validation failed - an actor of the other player was placed");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where two actors are placed at the same node
    moves = new ActorMove[] {
        new ActorMove(fantomas, n1, null),
        new ActorMove(joker, n1, null)
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, phantomClient);
      fail("Message validation failed - two actors were placed at the same position");
    }
    catch(ProtocolException e) {
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

   
    ActorMove[] moves = new ActorMove[] {
        new ActorMove(poirot, n1, null),
        new ActorMove(batman, n2, null)
    };
    MessageMove msg = new MessageMove(moves);
   
    // First try to verify it as a message from the detective client.
    // This should succeed, as the message contains a correct placement
    // of the detectives.
    g.verifyActorPlacement(msg, detectiveClient);
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

   
    // Try a message, where a phantom actor is missing
    ActorMove[] moves = new ActorMove[] {
        new ActorMove(batman, n1, null)
    };
    MessageMove msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, detectiveClient);
      fail("Message validation failed - not all actors were placed");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where one actor is placed multiple times
    moves = new ActorMove[] {
        new ActorMove(batman, n1, null),
        new ActorMove(poirot, n2, null),
        new ActorMove(batman, n3, null)
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, detectiveClient);
      fail("Message validation failed - an actor was placed multiple times");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where the transport type is specified for some
    // of the actors
    moves = new ActorMove[] {
        new ActorMove(batman, n1, tram),
        new ActorMove(poirot, n2, null)
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, detectiveClient);
      fail("Message validation failed - transport type was specified for an actor");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where the target node is missing for some of
    // the actors.
    moves = new ActorMove[] {
        new ActorMove(batman, null, tram),
        new ActorMove(poirot, n2, null),
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, detectiveClient);
      fail("Message validation failed - target node was not specified for an actor");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where a detective actor is placed
    moves = new ActorMove[] {
        new ActorMove(poirot, n1, null),
        new ActorMove(joker, n2, null),
        new ActorMove(batman, n3, null)
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, detectiveClient);
      fail("Message validation failed - an actor of the other player was placed");
    }
    catch(ProtocolException e) {
    }
   
    // Try a message, where two actors are placed at the same node
    moves = new ActorMove[] {
        new ActorMove(batman, n1, null),
        new ActorMove(poirot, n1, null)
    };
    msg = new MessageMove(moves);
    try {
      g.verifyActorPlacement(msg, detectiveClient);
      fail("Message validation failed - two actors were placed at the same position");
    }
    catch(ProtocolException e) {
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

   
    ActorMove[] moves = new ActorMove[] {
        new ActorMove(fantomas, n1, null),
        new ActorMove(joker, n3, null)
    };
    g.placeActors(new MessageMove(moves));
    moves = new ActorMove[] {
        new ActorMove(poirot, n2, null),
        new ActorMove(batman, n4, null)
    };
    g.placeActors(new MessageMove(moves));
   
    assertSame(n1, fantomas.getCurrentPosition());
    assertSame(n3, joker.getCurrentPosition());
    assertSame(n2, poirot.getCurrentPosition());
    assertSame(n4, batman.getCurrentPosition());
   
    assertEquals(1, fantomas.getNumberOfTickets(tram));
    assertEquals(1, fantomas.getNumberOfTickets(bus));
    assertEquals(0, fantomas.getNumberOfTickets(universal));
   
    assertEquals(1, joker.getNumberOfTickets(tram));
    assertEquals(1, joker.getNumberOfTickets(bus));
    assertEquals(0, fantomas.getNumberOfTickets(universal));
   
    // Try to move the actors to different places
    moves = new ActorMove[] {
        new ActorMove(fantomas, n6, bus),
        new ActorMove(joker, n4, tram)
    };
    g.moveActors(g.getActors(ClientType.PHANTOM), new MessageMove(moves));
   
    assertSame(n6, fantomas.getCurrentPosition());
    assertSame(n4, joker.getCurrentPosition());
   
    assertEquals(1, fantomas.getNumberOfTickets(tram));
    assertEquals(0, fantomas.getNumberOfTickets(bus));
    assertEquals(0, fantomas.getNumberOfTickets(universal));
   
    assertEquals(0, joker.getNumberOfTickets(tram));
    assertEquals(1, joker.getNumberOfTickets(bus));
    assertEquals(0, joker.getNumberOfTickets(universal));
   
    // Try to move back to the previous position. This should fail,
    // as the phantoms do not have enough tickets
    moves = new ActorMove[] {
        new ActorMove(fantomas, n1, bus),
        new ActorMove(joker, n3, tram)
    };
    try {
      g.moveActors(g.getActors(ClientType.PHANTOM), new MessageMove(moves));
      fail("Movement validation failed - the actors do not have enough tickets");
    }
    catch(ProtocolException e) {
    }
  }
View Full Code Here

Examples of cz.matfyz.aai.fantom.message.MessageMove

   
    ActorMove[] moves = new ActorMove[] {
        new ActorMove(fantomas, n1, null),
        new ActorMove(joker, n2, null)
    };
    g.placeActors(new MessageMove(moves));
    moves = new ActorMove[] {
        new ActorMove(poirot, n3, null),
        new ActorMove(batman, n4, null)
    };
    g.placeActors(new MessageMove(moves));
   
    assertSame(n1, fantomas.getCurrentPosition());
    assertSame(n2, joker.getCurrentPosition());
    assertSame(n3, poirot.getCurrentPosition());
    assertSame(n4, batman.getCurrentPosition());
   
    assertEquals(1, fantomas.getNumberOfTickets(tram));
    assertEquals(1, fantomas.getNumberOfTickets(bus));
    assertEquals(0, fantomas.getNumberOfTickets(universal));
   
    assertEquals(1, joker.getNumberOfTickets(tram));
    assertEquals(1, joker.getNumberOfTickets(bus));
    assertEquals(0, fantomas.getNumberOfTickets(universal));
   
    moves = new ActorMove[] {
        new ActorMove(fantomas, n6, bus),
        new ActorMove(joker, n1, tram)
    };
    g.moveActors(g.getActors(ClientType.PHANTOM), new MessageMove(moves));
   
    assertEquals(1, fantomas.getNumberOfTickets(tram));
    assertEquals(0, fantomas.getNumberOfTickets(bus));
    assertEquals(0, fantomas.getNumberOfTickets(universal));
   
    assertEquals(0, joker.getNumberOfTickets(tram));
    assertEquals(1, joker.getNumberOfTickets(bus));
    assertEquals(0, joker.getNumberOfTickets(universal));
   
    moves = new ActorMove[] {
        new ActorMove(fantomas, n5, tram),
        new ActorMove(joker, n6, bus)
    };
    g.moveActors(g.getActors(ClientType.PHANTOM), new MessageMove(moves));
   
    assertEquals(0, fantomas.getNumberOfTickets(tram));
    assertEquals(0, fantomas.getNumberOfTickets(bus));
    assertEquals(0, fantomas.getNumberOfTickets(universal));
   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.