Package cz.matfyz.aai.fantom.message

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


    phantomClient.sendMessage(msgStart);
    logger.trace("Message sent");
   
    // Place the detectives.
    logger.trace("Receiving actor placement from the detectives");
    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;
View Full Code Here


  protected MessageUpdate runRound(List<Actor> phantoms, List<Actor> detectives, int round) throws ServerException {
    logger.info(String.format("Playing round %d.", round));
    // Get the phantom moves.
   
    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;
View Full Code Here

      break;
    case PHANTOM:
      phantomWins++;
    }
   
    Message detectiveMsg = null;
    Message phantomMsg = null;
    if(winner.getMoves().length == 0) {
      detectiveMsg = winner;
      phantomMsg = winner;
    }
    else {
View Full Code Here

   *
   * @throws ServerException if there is a problem with sending the message.
   */
  protected void quit() throws ServerException {
    logger.info("Sending the 'quit' message to clients");
    Message msg = new MessageQuit();
    logger.debug("Sending the 'quit' message to detectives");
    detectiveClient.sendMessage(msg);
    logger.debug("Sending the 'quit' message to phantoms");
    phantomClient.sendMessage(msg);
    logger.debug("The message was sent");
View Full Code Here

  /**
   * Runs the client using {@link #agent} for decision making.
   */
  public void run() throws ServerException {
    try {
      Message msg = null;
     
      setStreams(System.in, System.out, null);
     
      msg = new MessageReady(agent.getName(), agent.getClientType());
      sendMessage(msg);
     
      tournament_loop:
      while(true) {
        msg = receiveMessage(null);
        if(msg instanceof MessageStart) {
          this.graph = ((MessageStart)msg).getGraph();
          this.graphReadOnly = new GraphReadOnly(this.graph);
          agent.start(graphReadOnly);
         
          sentPlacement = false;
         
          if(agent.getClientType() == ClientType.DETECTIVE)
            sendMoves();
         
          while(true) {
            msg = receiveMessage(graph);
            if(!(msg instanceof MessageUpdate))
              throw new ProtocolException(String.format("Message 'update' was expected, got '%s'", msg.getMessageType()), null);

            MessageUpdate msgUpdate = (MessageUpdate)msg;
           
            // Update the agent, if nobody did win the game in the last round, or if there
            // is information about movements of the other agent (e.g. about the movement
            // of the detectives, that captured the phantom, or the movement of the phantom
            // that commited suicide).
            if(msgUpdate.getWinner() == null || msgUpdate.getMoves().length > 0)
              receiveUpdate(msgUpdate);
            // If there is a winner, end the round
            if(msgUpdate.getWinner() != null) {
              agent.end(msgUpdate.getWinner());
              continue tournament_loop;
            }
           
            sendMoves();
          }
        }
        else if(msg instanceof MessageQuit) {
          agent.quit();
          return;
        }
        else {
          throw new ProtocolException("Unexpected message type: " + msg.getMessageType(), null);
        }
      }
    }
    catch(Throwable e) {
      e.printStackTrace();
View Full Code Here

    } catch (IOException e) {
      throw new ServerException("Initialization of the communication with the client failed");
    }

    logger.debug("Waiting for 'ready' from the client");
    Message msg = receiveMessage(null);
    if(!(msg instanceof MessageReady))
      throw new ProtocolException("The 'ready' message was expected", this);

    MessageReady msgReady = (MessageReady)msg;
    this.clientName = msgReady.getClientName();
View Full Code Here

TOP

Related Classes of cz.matfyz.aai.fantom.message.Message

Copyright © 2018 www.massapicom. 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.