Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.06 KB | None | 0 0
  1.  
  2. import java.util.*;
  3. import java.io.*;
  4. import java.math.*;
  5.  
  6.  
  7. class Player {
  8.  
  9.  
  10.     public static void main(String args[]) {
  11.         Scanner in = new Scanner(System.in);
  12.         int myTeamId = in.nextInt();
  13.         Global.setTeamIds(myTeamId);
  14.  
  15.  
  16.         while(true)
  17.         {
  18.             ArrayList<Wizard> CollectionWizard  = new ArrayList<>();
  19.             ArrayList<Snaffle> CollectionSnaffle  = new ArrayList<>();
  20.             Snaffle.resetNbSnaffle(); // RESET LE NOMBRE DE SNAFFLE A 0 A CHAQUE DEBUT DE ROUND
  21.             Wizard.resetSnaffleTaken();
  22.             int myScore = in.nextInt();
  23.             int myMagic = in.nextInt();
  24.             int opponentScore = in.nextInt();
  25.             int opponentMagic = in.nextInt();
  26.             int entities = in.nextInt();
  27.  
  28.             Global.setMyMana(myMagic);
  29.             for (int i=0;i<entities;i++)
  30.             {
  31.                 int entityId = in.nextInt();
  32.                 String entityType = in.next(); // "WIZARD", "OPPONENT_WIZARD" or "SNAFFLE" (or "BLUDGER" after first league)
  33.                 int x = in.nextInt(); // position
  34.                 int y = in.nextInt(); // position
  35.                 int vx = in.nextInt(); // velocity
  36.                 int vy = in.nextInt(); // velocity
  37.                 int state = in.nextInt(); // 1 if the wizard is holding a Snaffle, 0 otherwise
  38.  
  39.                 if (entityType.equals("WIZARD"))
  40.                 {
  41.                     CollectionWizard.add(new Wizard(entityId,new Point(x,y),state,Global.getMyTeamId()));
  42.                                         System.err.println(Global.getMyTeamId());
  43.  
  44.                 }
  45.                 if (entityType.equals("OPPONENT_WIZARD"))
  46.                 {
  47.                     CollectionWizard.add(new Wizard(entityId,new Point(x,y),state,Global.getHisTeamId()));
  48.                 }
  49.                 if(entityType.equals("SNAFFLE"))
  50.                 {
  51.                     CollectionSnaffle.add(new Snaffle(entityId,new Point(x,y)));
  52.                 }
  53.             }
  54.  
  55.             for(int i =0;i<4;i++)
  56.             {
  57.                 if (CollectionWizard.get(i).getTeam() == myTeamId)
  58.                 {
  59.                     String move = CollectionWizard.get(i).Move(CollectionWizard,CollectionSnaffle);
  60.                     System.out.println(move);
  61.                 }
  62.             }
  63.         }
  64.     }
  65.  
  66. }
  67.  
  68. class Global {
  69.     private static int myTeamId;
  70.     private static int hisTeamId;
  71.     private static Point goalToShoot = new Point(0,0);
  72.     private static int myMana;
  73.  
  74.     public static void setTeamIds(int TeamId)
  75.     {
  76.         if  (TeamId == 0 )
  77.         {
  78.             goalToShoot.setX(16000);
  79.             goalToShoot.setY(3750);
  80.             hisTeamId = 1;
  81.             myTeamId = TeamId;
  82.            
  83.         }
  84.         else
  85.         {
  86.             goalToShoot.setX(0);
  87.             goalToShoot.setY(3750);
  88.             hisTeamId = 0;
  89.             myTeamId = TeamId;
  90.         }
  91.     }
  92.  
  93.     public static int getMyMana()
  94.     {
  95.         return myMana;
  96.     }
  97.     public static void setMyMana(int Mana)
  98.     {
  99.         myMana = Mana;
  100.     }
  101.     private static void setHisTeamId(int TeamId)
  102.     {
  103.         hisTeamId = TeamId;
  104.     }
  105.  
  106.     public static int getMyTeamId()
  107.     {
  108.         return myTeamId;
  109.     }
  110.     public static int getHisTeamId()
  111.     {
  112.         return hisTeamId;
  113.     }
  114.  
  115.     private static void setGoalPos()
  116.     {
  117.         if (myTeamId == 0)
  118.         {
  119.             goalToShoot = new Point(16000,3750);
  120.         }
  121.         else
  122.         {
  123.             goalToShoot = new Point(0,3750);
  124.         }
  125.     }
  126.  
  127.     public static Point getGoalPos()
  128.     {
  129.         return goalToShoot;
  130.     }
  131. }
  132. class Point {
  133.     private int x;
  134.     private int y;
  135.  
  136.     public Point(int x,int y)
  137.     {
  138.         this.x = x;
  139.         this.y = y;
  140.     }
  141.  
  142.     public int getX()
  143.     {
  144.         return this.x;
  145.     }
  146.     public int getY()
  147.     {
  148.         return this.y;
  149.     }
  150.     public void setX(int X)
  151.     {
  152.         x = X;
  153.     }
  154.     public void setY(int Y)
  155.     {
  156.         y = Y;
  157.     }
  158.  
  159.     public float calculateDistance(Point p2)
  160.     {
  161.         return ((x - p2.getX()) * (x - p2.getX())) + ((y - p2.getY()) * (y - p2.getY()));
  162.     }
  163. }
  164.  
  165. class Snaffle
  166. {
  167.     private int id;
  168.     private Point pos;
  169.     private static int nbSnaffle;
  170.  
  171.     public Snaffle(int id, Point pos)
  172.     {
  173.         this.id = id;
  174.         this.pos = pos;
  175.         ++nbSnaffle;
  176.     }
  177.  
  178.     public Point getPos()
  179.     {
  180.         return this.pos;
  181.     }
  182.  
  183.     public int getId()
  184.     {
  185.         return this.id;
  186.     }
  187.  
  188.     public static int getNbSnaffle()
  189.     {
  190.         return nbSnaffle;
  191.     }
  192.     public static void resetNbSnaffle()
  193.     {
  194.         nbSnaffle = 0;
  195.     }
  196. }
  197.  
  198. class Wizard {
  199.     private int id;
  200.     private Point pos;
  201.     private int snaffleGrab; // null if no snaffle grabbed
  202.     private int team;
  203.     private static Snaffle snaffleTaken; // snafflé déjà pris
  204.  
  205.  
  206.     public Wizard (int id, Point pos, int snaffle, int team)
  207.     {
  208.         this.id = id;
  209.         this.pos = pos;
  210.         this.snaffleGrab = snaffle;
  211.         this.team = team;
  212.  
  213.     }
  214.  
  215.     public String Move(ArrayList<Wizard> CollectionWizard,ArrayList<Snaffle> CollectionSnaffle)
  216.     {
  217.      
  218.         /*If the wizard has a snaffle, throw it*/
  219.         if (this.getSnaffleGrab() == 1)
  220.         {
  221.             return  "THROW " + Global.getGoalPos().getX() + " " + Global.getGoalPos().getY() + " 500";
  222.         }
  223.           /* Test if the current wizard have to cast a spell */
  224.         String nextMove = null;
  225.         nextMove = canCastSpell(CollectionWizard,CollectionSnaffle);
  226.         if (nextMove != null)
  227.         {
  228.             return nextMove;
  229.         }
  230.  
  231.         /* If the wizard doesn't have a snaffle , take one*/
  232.         Snaffle snaffleTarget = getNearestSnaffle(CollectionSnaffle);
  233.         if  (snaffleTarget != null)
  234.         {
  235.             return "MOVE " + snaffleTarget.getPos().getX() + " " + snaffleTarget.getPos().getY() + " 150";
  236.         }
  237.  
  238.         nextMove = attackEnemy(CollectionWizard);
  239.  
  240.         return nextMove;
  241.     }
  242.  
  243.     private String canCastSpell(ArrayList<Wizard> CollectionWizard,ArrayList<Snaffle> CollectionSnaffle)
  244.     {
  245.         if (Global.getMyMana() < 10)
  246.         {
  247.             return null;
  248.         }
  249.         /* Si il n'y a qu'un seul snaffle, on utilise ACCIO */
  250.         System.err.println(Snaffle.getNbSnaffle());
  251.         if (Snaffle.getNbSnaffle() == 1 && Global.getMyMana() >= 15)
  252.         {
  253.             /* On regarde quel Wizard est plus près du but pour effectuer ACCIO */
  254.             for (int i=0; i<2;i++)
  255.             {
  256.                 if (CollectionWizard.get(i).getTeam() == Global.getMyTeamId() && CollectionWizard.get(i).getId() != this.id)
  257.                 {
  258.                     if (CollectionWizard.get(i).getPos().calculateDistance(Global.getGoalPos()) > this.pos.calculateDistance(Global.getGoalPos()))
  259.                     {
  260.                                    return "ACCIO " + CollectionSnaffle.get(0).getId();
  261.                     }
  262.                 }
  263.             }
  264.         }
  265.         /* On test si le pouvoir Flipendo est worth dans ce cas*/
  266.         if(Snaffle.getNbSnaffle() > 1 && Global.getMyMana() >= 20 )
  267.         {
  268.             for (int i = 0;i<CollectionSnaffle.size();i++) //Calculer si on peut faire un flippendo
  269.             {
  270.                 if (Global.getMyTeamId() == 0)
  271.                 {
  272.                     if (CollectionSnaffle.get(i).getPos().getX() > this.pos.getX())
  273.                     {
  274.                         return "FLIPENDO " + CollectionSnaffle.get(i).getId();
  275.                     }
  276.                 }
  277.                 if (Global.getMyTeamId() == 1)
  278.                 {
  279.                     if (CollectionSnaffle.get(i).getPos().getX() < this.pos.getX())
  280.                     {
  281.                         return "FLIPENDO " + CollectionSnaffle.get(i).getId();
  282.                     }
  283.                 }
  284.             }
  285.         }
  286.  
  287.         return null;
  288.     }
  289.  
  290.     private String attackEnemy(ArrayList<Wizard> CollectionWizard)
  291.     {
  292.         System.err.println("JATTAQUE");
  293.         Wizard target = null;
  294.         for (int i=0;i<CollectionWizard.size();i++)
  295.         {
  296.             if (CollectionWizard.get(i).getTeam() != Global.getMyTeamId())
  297.             {
  298.                 if (CollectionWizard.get(i).getSnaffleGrab() == 1)
  299.                 {
  300.                     return "MOVE " + CollectionWizard.get(i).getPos().getX() + " " + CollectionWizard.get(i).getPos().getY() + " 150";
  301.                 }
  302.                 else
  303.                 {
  304.                     target = CollectionWizard.get(i);
  305.                 }
  306.             }
  307.         }
  308.         return "MOVE " + target.getPos().getX() + " " + target.getPos().getY() + " 150";
  309.  
  310.     }
  311.  
  312.     private Snaffle getNearestSnaffle(ArrayList<Snaffle> CollectionSnaffle)
  313.     {
  314.         Snaffle nearestSnaffle = null;
  315.         float nearestSnaffleDistance = Float.MAX_VALUE;
  316.         for (int i=0;i<CollectionSnaffle.size();i++)
  317.         {
  318.             float currentDistance = CollectionSnaffle.get(i).getPos().calculateDistance(this.pos);
  319.             if (currentDistance < nearestSnaffleDistance)
  320.             {
  321.                 if  (snaffleTaken != null)
  322.                 {
  323.                     if (snaffleTaken.getId() != CollectionSnaffle.get(i).getId())
  324.                     {
  325.                         nearestSnaffle = CollectionSnaffle.get(i);
  326.                         nearestSnaffleDistance = currentDistance;
  327.                     }
  328.                 }
  329.                 else
  330.                 {
  331.                     nearestSnaffle = CollectionSnaffle.get(i);
  332.                     nearestSnaffleDistance = currentDistance;
  333.                 }
  334.  
  335.             }
  336.         }
  337.         snaffleTaken = nearestSnaffle;
  338.         return nearestSnaffle;
  339.     }
  340.     public Point getPos()
  341.     {
  342.         return this.pos;
  343.     }
  344.  
  345.     public int getSnaffleGrab()
  346.     {
  347.         return this.snaffleGrab;
  348.     }
  349.  
  350.     public int getTeam()
  351.     {
  352.         return this.team;
  353.     }
  354.  
  355.     public int getId()
  356.     {
  357.         return this.id;
  358.     }
  359.     public static void resetSnaffleTaken()
  360.     {
  361.         snaffleTaken = null;
  362.     }
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement