⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clearancedeliveryagent.java.svn-base

📁 這是一個JAVA語言寫的多代理人程式用來模擬飛機起飛或是降落的程式
💻 SVN-BASE
字号:
package agents;

import java.util.*;

import world.*;
import base.*;
import interfaces.*;

public class ClearanceDeliveryAgent extends Agent implements ClearanceDeliveryInterface {

		List<Strip> strips;
		Tower tower;
		String name;

		public ClearanceDeliveryAgent(String newname, Tower newtower) {
			super();
			name  = newname;
			tower = newtower;
			strips = new ArrayList<Strip>();
		}

		/* Messages
		 * Takeoff / Landing Scenario
		 *
		 */

		// Take off scenario
		public void msgNewDepartingFlight(Plane plane, String callNumber, Runway runway, Gate gate, String destination, PilotInterface p) {
			print("Received msgNewDepartingFlight");
			Strip strip = new Strip(callNumber);
			strip.runway = runway;
			strip.gate = gate;
			strip.cd_flight_state = Strip.CDFlightState.NO_ACTION;
			strips.add(strip);
			print("New strip: " + strip.toString());
			stateChanged();
		}
		public void msgRequestingClearance(String callNumber, Gate gate) {
			print("Received msgRequestingClearance");
			Strip tempstrip;
			tempstrip = get_strip(callNumber);
			tempstrip.cd_flight_state = Strip.CDFlightState.REQUESTING_CLEARANCE;
			stateChanged();
		}
		public void msgConfirmClearance(String callNumber, GroundControllerInterface groundController) {
			print("Received msgConfirmClearance");
			Strip tempstrip;
			tempstrip = get_strip(callNumber);
			tempstrip.cd_flight_state = Strip.CDFlightState.CONFIRM_CLEARANCE_GRANTED;
			stateChanged();
		}
		public void msgConfirmWeather(String callNumber) {
			print("Received msgConfirmWeather");
			Strip tempstrip;
			tempstrip = get_strip(callNumber);
			tempstrip.cd_flight_state = Strip.CDFlightState.CONFIRM_WEATHER;
			stateChanged();
		}

		/* Scheduler
		 *
		 *
		 */
		public boolean pickAndExecuteAnAction() {

			Strip temp_strip;

			if((temp_strip = get_strip(Strip.CDFlightState.NO_ACTION)) != null) {

			}
			// Take off schedules
			if((temp_strip = get_strip(Strip.CDFlightState.REQUESTING_CLEARANCE)) != null) {
				DoClearanceGranted(temp_strip.callNum);
				return true;
			}
			if((temp_strip = get_strip(Strip.CDFlightState.CONFIRM_CLEARANCE_GRANTED)) != null) {
				DoSendWeather(temp_strip.callNum, temp_strip);
				return true;
			}
			if((temp_strip = get_strip(Strip.CDFlightState.CONFIRM_WEATHER)) != null) {
				DoConfirmWeather(temp_strip);
				return true;
			}

			return false;
		}

		/* Actions
		 *
		 */

		// Actions for Take off Scenario
		public void DoClearanceGranted(String callnum) {
			Strip temp_strip;
			print("Sending pilot msgClearanceGranted");
			List<Waypoint> points = null; // hack to get waypoint to work
			temp_strip = get_strip(callnum);
			temp_strip.cd_flight_state = Strip.CDFlightState.NO_ACTION;
			getPilot(callnum).msgClearanceGranted(points, World.get_ground_controller(tower));
			stateChanged();
		}

		public void DoSendWeather(String callnum, Strip strip) {
			print("Sending ground controller msgNewDepartureStrip");
			Strip temp_strip;
			Weather report = new Weather();
			temp_strip = get_strip(callnum);
			temp_strip.cd_flight_state = Strip.CDFlightState.NO_ACTION;
			// world.get_ground_controller(tower).msgNewDepartureStrip(strip);
			World.get_ground_controller(tower).msgNewDepartureStrip(strip);
			getPilot(callnum).msgSendWeather(report);
			stateChanged();
		}
		
		public void DoConfirmWeather(Strip strip) {
			strip.cd_flight_state = Strip.CDFlightState.NO_ACTION;
			stateChanged();
		}

		// Subroutines
		public Strip get_strip(String cn) {
			for (Strip strip : strips)
				if (strip.callNum.equals(cn))
					return strip;
			return null;
		}

		public Strip get_strip(Strip.CDFlightState state) {
			if(strips.size() > 0) {
			for (Strip strip : strips)
				if (strip.cd_flight_state == state)
					return strip;
			}
			return null;
		}

		public PilotInterface getPilot(String callnumber) {
			Plane plane;
			plane = World.get_plane(callnumber);
			return plane.radio();


		}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -