Final Project: Disaster Relief Robots

在这里插入图片描述

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;

/**
 * COMP90041, Sem1, 2023: Final Project
 * @author:
 * student id: 
 * student email: 
 */
public class RescueBot {
    public static List<Scenario> scenarioList = new ArrayList<>();

    /**
     * Decides whether to save the passengers or the pedestrians
     * @param scenario: the ethical dilemma
     */
    public static void decide(Scenario scenario) {
        // a very simple decision engine
        // TODO: take into account at least 5 characteristics
        scenario.setJudged(true);
        for(Location location : scenario.getLocationList()){
            // if is trespassing don't choice
            if(location.isTrespassing()){
                continue;
            }
            // if average age below 40 save this location
            if(location.getAverageAge() < 40){
                location.setSaved(true);
                return;
            }
            // if location has pregnant save
            if(location.hasPregnant()){
                location.setSaved(true);
                return;
            }

            if(location.hasSpecialAnimal()){
                location.setSaved(true);
                return;
            }

            if(location.hasFemale()){
                location.setSaved(true);
                return;
            }
        }
        // random choice
        Random random = new Random();
        int i = random.nextInt(0, scenario.getLocationList().size());
        scenario.getLocationList().get(i).setSaved(true);
    }

    /**
     * Program entry
     */
    public static void main(String[] args) {
        getArgs(args);
        UserOutput.welcome();
        ReadFromFile readFromFile = new ReadFromFile();
        if(ProgramSet.scenarioPath != null){
            readFromFile.readFromCSV(scenarioList, ProgramSet.scenarioPath);
            System.out.println(scenarioList.size() + " scenarios imported.");
        }

        String option;
        while(true){
            try {
                UserOutput.showCommands();
                option = UserInput.scanner.next();
                if (Objects.equals(option, "judge") || Objects.equals(option, "j")) {

                    MainMenu.judge(scenarioList);
                    System.out.print(" ");

                } else if (Objects.equals(option, "run") || Objects.equals(option, "r")) {

                    MainMenu.runSimulation(scenarioList);
                    System.out.print(" ");

                } else if (Objects.equals(option, "audit") || Objects.equals(option, "a")) {

                    MainMenu.audit(scenarioList);
                    System.out.print(" ");

                } else if (Objects.equals(option, "quit") || Objects.equals(option, "q")) {

                    System.exit(0);

                } else {
                    UserOutput.showInvalidCommands();
                }
            }catch(Exception ignore){}
        }
    }

    private static void getArgs(String[] args) {
        if(args.length == 0){
            return;
        }
        if(Objects.equals(args[0], "-h") || Objects.equals(args[0], "--help")){
            UserOutput.help();
        }

        for(int i = 0; i < args.length - 1; i++){
            if(Objects.equals(args[i], "-s") || Objects.equals(args[i], "--scenarios")){
                String path = args[i + 1];
                try(InputStream inputStream = new FileInputStream(path)){
                    ProgramSet.scenarioPath = path;
                }catch(FileNotFoundException e){
                    System.out.println("java.io.FileNotFoundException: could not find scenarios file.");
                    UserOutput.help();
                }catch(IOException ignore){}
            }
            else if(Objects.equals(args[i], "-l") || Objects.equals(args[i], "--log")){
                ProgramSet.logPath = args[i + 1];
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值