Skip to content

Instantly share code, notes, and snippets.

@TrevCan
Last active October 11, 2020 03:20
Show Gist options
  • Save TrevCan/39f90d7aed4d129d34bd2a839b1f5701 to your computer and use it in GitHub Desktop.
Save TrevCan/39f90d7aed4d129d34bd2a839b1f5701 to your computer and use it in GitHub Desktop.
Generates an FRC Robot randomly and deteremines its probability.
public class RobotFactory {
/*
Construye un programa que de manera automática determine los componentes que un robot va a tener:
1. Chasis: butterfly, dragonfly, kiwi - 3
2. Intake: rollers, claw, pneumatic claw - 3
3. Climber: pneumatic climber, belts, brute force - 3
4. Shooters: catapult, shooting rollers, gravity - 3
(Solo se puede elegir uno de cada cosa)
Aleatoriamente se deben construir los robots. Si existen componentes que no pueden asociarse, al final deberá mostrar un WARNING indicando los pares de componentes que no pueden estar juntos.
REGLAS:
1. El chasis: kiwi no puede llevar shooters: gravity
2. El chasis butterfly: no puede llevar intake: rollers
3. Intake: pneumatic claw no puede ir junto con climber: brute force
4. Climber belts no puede llevar shooters: catapult
*/
//chassis, intake, climber, shooters, warnings
public static int warnings = 0;
public static double probability = 0;
public static void main(String[] args) {
Chassis chassis = getChassis((int) (Math.random() * 2));
Intake intake = getIntake((int) (Math.random() * 2));
Climber climber = getClimber((int) (Math.random() * 2));
Shooter shooter = getShooter((int) (Math.random() * 2));
probability = chassis.probability * shooter.probability * intake.probability + climber.probability;
System.out.println(chassis + "\n" + intake + "\n" + climber + "\n" + shooter + "\n------------");
if (chassis == Chassis.KIWI && shooter == Shooter.GRAVITY) {
showWarning(chassis, shooter);
}
if (chassis == Chassis.BUTTERFLY && intake == Intake.ROLLERS) {
showWarning(chassis, intake);
}
if (intake == Intake.PNEUMATIC_CLAW && climber == Climber.BRUTE_FORCE) {
showWarning(intake, climber);
}
if (climber == Climber.BELTS && shooter == Shooter.CATAPULT) {
showWarning(climber, shooter);
}
System.out.println("Total warnings: " + warnings);
System.out.println("Robot Probability: " + probability);
}
public static void showWarning(Object object, Object object1) {
System.out.printf("\nWarning: %s and %s may have compatibility issues.", object, object1);
warnings++;
probability *= 0.9;
}
enum Chassis {
BUTTERFLY(0.7),
DRAGONFLY(0.8),
KIWI(0.3);
double probability;
Chassis(double probability) {
this.probability = probability;
}
public String toString() {
return "Chassis " + this.name();
}
}
static Chassis getChassis(int index) {
switch (index) {
case 1:
return Chassis.DRAGONFLY;
case 2:
return Chassis.KIWI;
default:
return Chassis.BUTTERFLY;
}
}
enum Intake {
ROLLERS(0.5),
CLAW(0.3),
PNEUMATIC_CLAW(0.6);
double probability;
Intake(double probability) {
this.probability = probability;
}
public String toString() {
return "Intake " + this.name();
}
}
static Intake getIntake(int index) {
switch (index) {
case 1:
return Intake.CLAW;
case 2:
return Intake.PNEUMATIC_CLAW;
default:
return Intake.ROLLERS;
}
}
enum Climber {
PNEUMATIC_CLIMBER(0.7),
BELTS(0.5),
BRUTE_FORCE(0.4);
double probability;
Climber(double probability) {
this.probability = probability;
}
public String toString() {
return "Climber " + this.name();
}
}
static Climber getClimber(int index) {
switch (index) {
case 1:
return Climber.BELTS;
case 2:
return Climber.BRUTE_FORCE;
default:
return Climber.PNEUMATIC_CLIMBER;
}
}
enum Shooter {
CATAPULT(0.5),
SHOOTING_ROLLERS(0.8),
GRAVITY(0.2);
double probability;
Shooter(double probability) {
this.probability = probability;
}
public String toString() {
return "Shooter " + this.name();
}
}
static Shooter getShooter(int index) {
switch (index) {
case 1:
return Shooter.SHOOTING_ROLLERS;
case 2:
return Shooter.GRAVITY;
default:
return Shooter.CATAPULT;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment