Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- class Player {
- public static void main(String args[]) {
- Scanner in = new Scanner(System.in);
- int myTeamId = in.nextInt();
- Global.setTeamIds(myTeamId);
- while(true)
- {
- ArrayList<Wizard> CollectionWizard = new ArrayList<>();
- ArrayList<Snaffle> CollectionSnaffle = new ArrayList<>();
- Snaffle.resetNbSnaffle(); // RESET LE NOMBRE DE SNAFFLE A 0 A CHAQUE DEBUT DE ROUND
- Wizard.resetSnaffleTaken();
- int myScore = in.nextInt();
- int myMagic = in.nextInt();
- int opponentScore = in.nextInt();
- int opponentMagic = in.nextInt();
- int entities = in.nextInt();
- Global.setMyMana(myMagic);
- for (int i=0;i<entities;i++)
- {
- int entityId = in.nextInt();
- String entityType = in.next(); // "WIZARD", "OPPONENT_WIZARD" or "SNAFFLE" (or "BLUDGER" after first league)
- int x = in.nextInt(); // position
- int y = in.nextInt(); // position
- int vx = in.nextInt(); // velocity
- int vy = in.nextInt(); // velocity
- int state = in.nextInt(); // 1 if the wizard is holding a Snaffle, 0 otherwise
- if (entityType.equals("WIZARD"))
- {
- CollectionWizard.add(new Wizard(entityId,new Point(x,y),state,Global.getMyTeamId()));
- System.err.println(Global.getMyTeamId());
- }
- if (entityType.equals("OPPONENT_WIZARD"))
- {
- CollectionWizard.add(new Wizard(entityId,new Point(x,y),state,Global.getHisTeamId()));
- }
- if(entityType.equals("SNAFFLE"))
- {
- CollectionSnaffle.add(new Snaffle(entityId,new Point(x,y)));
- }
- }
- for(int i =0;i<4;i++)
- {
- if (CollectionWizard.get(i).getTeam() == myTeamId)
- {
- String move = CollectionWizard.get(i).Move(CollectionWizard,CollectionSnaffle);
- System.out.println(move);
- }
- }
- }
- }
- }
- class Global {
- private static int myTeamId;
- private static int hisTeamId;
- private static Point goalToShoot = new Point(0,0);
- private static int myMana;
- public static void setTeamIds(int TeamId)
- {
- if (TeamId == 0 )
- {
- goalToShoot.setX(16000);
- goalToShoot.setY(3750);
- hisTeamId = 1;
- myTeamId = TeamId;
- }
- else
- {
- goalToShoot.setX(0);
- goalToShoot.setY(3750);
- hisTeamId = 0;
- myTeamId = TeamId;
- }
- }
- public static int getMyMana()
- {
- return myMana;
- }
- public static void setMyMana(int Mana)
- {
- myMana = Mana;
- }
- private static void setHisTeamId(int TeamId)
- {
- hisTeamId = TeamId;
- }
- public static int getMyTeamId()
- {
- return myTeamId;
- }
- public static int getHisTeamId()
- {
- return hisTeamId;
- }
- private static void setGoalPos()
- {
- if (myTeamId == 0)
- {
- goalToShoot = new Point(16000,3750);
- }
- else
- {
- goalToShoot = new Point(0,3750);
- }
- }
- public static Point getGoalPos()
- {
- return goalToShoot;
- }
- }
- class Point {
- private int x;
- private int y;
- public Point(int x,int y)
- {
- this.x = x;
- this.y = y;
- }
- public int getX()
- {
- return this.x;
- }
- public int getY()
- {
- return this.y;
- }
- public void setX(int X)
- {
- x = X;
- }
- public void setY(int Y)
- {
- y = Y;
- }
- public float calculateDistance(Point p2)
- {
- return ((x - p2.getX()) * (x - p2.getX())) + ((y - p2.getY()) * (y - p2.getY()));
- }
- }
- class Snaffle
- {
- private int id;
- private Point pos;
- private static int nbSnaffle;
- public Snaffle(int id, Point pos)
- {
- this.id = id;
- this.pos = pos;
- ++nbSnaffle;
- }
- public Point getPos()
- {
- return this.pos;
- }
- public int getId()
- {
- return this.id;
- }
- public static int getNbSnaffle()
- {
- return nbSnaffle;
- }
- public static void resetNbSnaffle()
- {
- nbSnaffle = 0;
- }
- }
- class Wizard {
- private int id;
- private Point pos;
- private int snaffleGrab; // null if no snaffle grabbed
- private int team;
- private static Snaffle snaffleTaken; // snafflé déjà pris
- public Wizard (int id, Point pos, int snaffle, int team)
- {
- this.id = id;
- this.pos = pos;
- this.snaffleGrab = snaffle;
- this.team = team;
- }
- public String Move(ArrayList<Wizard> CollectionWizard,ArrayList<Snaffle> CollectionSnaffle)
- {
- /*If the wizard has a snaffle, throw it*/
- if (this.getSnaffleGrab() == 1)
- {
- return "THROW " + Global.getGoalPos().getX() + " " + Global.getGoalPos().getY() + " 500";
- }
- /* Test if the current wizard have to cast a spell */
- String nextMove = null;
- nextMove = canCastSpell(CollectionWizard,CollectionSnaffle);
- if (nextMove != null)
- {
- return nextMove;
- }
- /* If the wizard doesn't have a snaffle , take one*/
- Snaffle snaffleTarget = getNearestSnaffle(CollectionSnaffle);
- if (snaffleTarget != null)
- {
- return "MOVE " + snaffleTarget.getPos().getX() + " " + snaffleTarget.getPos().getY() + " 150";
- }
- nextMove = attackEnemy(CollectionWizard);
- return nextMove;
- }
- private String canCastSpell(ArrayList<Wizard> CollectionWizard,ArrayList<Snaffle> CollectionSnaffle)
- {
- if (Global.getMyMana() < 10)
- {
- return null;
- }
- /* Si il n'y a qu'un seul snaffle, on utilise ACCIO */
- System.err.println(Snaffle.getNbSnaffle());
- if (Snaffle.getNbSnaffle() == 1 && Global.getMyMana() >= 15)
- {
- /* On regarde quel Wizard est plus près du but pour effectuer ACCIO */
- for (int i=0; i<2;i++)
- {
- if (CollectionWizard.get(i).getTeam() == Global.getMyTeamId() && CollectionWizard.get(i).getId() != this.id)
- {
- if (CollectionWizard.get(i).getPos().calculateDistance(Global.getGoalPos()) > this.pos.calculateDistance(Global.getGoalPos()))
- {
- return "ACCIO " + CollectionSnaffle.get(0).getId();
- }
- }
- }
- }
- /* On test si le pouvoir Flipendo est worth dans ce cas*/
- if(Snaffle.getNbSnaffle() > 1 && Global.getMyMana() >= 20 )
- {
- for (int i = 0;i<CollectionSnaffle.size();i++) //Calculer si on peut faire un flippendo
- {
- if (Global.getMyTeamId() == 0)
- {
- if (CollectionSnaffle.get(i).getPos().getX() > this.pos.getX())
- {
- return "FLIPENDO " + CollectionSnaffle.get(i).getId();
- }
- }
- if (Global.getMyTeamId() == 1)
- {
- if (CollectionSnaffle.get(i).getPos().getX() < this.pos.getX())
- {
- return "FLIPENDO " + CollectionSnaffle.get(i).getId();
- }
- }
- }
- }
- return null;
- }
- private String attackEnemy(ArrayList<Wizard> CollectionWizard)
- {
- System.err.println("JATTAQUE");
- Wizard target = null;
- for (int i=0;i<CollectionWizard.size();i++)
- {
- if (CollectionWizard.get(i).getTeam() != Global.getMyTeamId())
- {
- if (CollectionWizard.get(i).getSnaffleGrab() == 1)
- {
- return "MOVE " + CollectionWizard.get(i).getPos().getX() + " " + CollectionWizard.get(i).getPos().getY() + " 150";
- }
- else
- {
- target = CollectionWizard.get(i);
- }
- }
- }
- return "MOVE " + target.getPos().getX() + " " + target.getPos().getY() + " 150";
- }
- private Snaffle getNearestSnaffle(ArrayList<Snaffle> CollectionSnaffle)
- {
- Snaffle nearestSnaffle = null;
- float nearestSnaffleDistance = Float.MAX_VALUE;
- for (int i=0;i<CollectionSnaffle.size();i++)
- {
- float currentDistance = CollectionSnaffle.get(i).getPos().calculateDistance(this.pos);
- if (currentDistance < nearestSnaffleDistance)
- {
- if (snaffleTaken != null)
- {
- if (snaffleTaken.getId() != CollectionSnaffle.get(i).getId())
- {
- nearestSnaffle = CollectionSnaffle.get(i);
- nearestSnaffleDistance = currentDistance;
- }
- }
- else
- {
- nearestSnaffle = CollectionSnaffle.get(i);
- nearestSnaffleDistance = currentDistance;
- }
- }
- }
- snaffleTaken = nearestSnaffle;
- return nearestSnaffle;
- }
- public Point getPos()
- {
- return this.pos;
- }
- public int getSnaffleGrab()
- {
- return this.snaffleGrab;
- }
- public int getTeam()
- {
- return this.team;
- }
- public int getId()
- {
- return this.id;
- }
- public static void resetSnaffleTaken()
- {
- snaffleTaken = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement