Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Com.CodeGame.CodeHockey2014.DevKit.CSharpCgdk.Model;
  4.  
  5. namespace Com.CodeGame.CodeHockey2014.DevKit.CSharpCgdk
  6. {
  7.     public sealed class MyStrategy : IStrategy
  8.     {
  9.         public void Move(Hockeyist self, World world, Game game, Move move)
  10.         {
  11.             move.SpeedUp = -1.0D;
  12.             move.Turn = Math.PI;
  13.             move.Action = ActionType.Strike;
  14.             if (world.Puck.OwnerPlayerId == world.GetMyPlayer().Id)
  15.             {
  16.                 // ШАЙБУ КОНТРОЛИРУЕТ ИГРОК
  17.             }
  18.             else if (world.Puck.OwnerPlayerId == world.GetOpponentPlayer().Id)
  19.             {
  20.                 // ШАЙБУ КОНТРОЛИРУЕТ ОППОНЕНТ
  21.                 var linesToBlock = new List<Line>();
  22.                 linesToBlock.Add(new Line()
  23.                     {
  24.                         A = new Point {X = world.Puck.X, Y = world.Puck.Y},
  25.                         B = new Point
  26.                             {
  27.                                 X = world.GetMyPlayer().NetFront,
  28.                                 Y = world.GetMyPlayer().NetTop +
  29.                                     (world.GetMyPlayer().NetTop - world.GetMyPlayer().NetBottom)/2d
  30.                             },
  31.                         LineType = LineType.GoalLine
  32.                     });
  33.  
  34.                 var OpponentHockeyists = new List<Hockeyist>();
  35.                 foreach (Hockeyist hockeyist in world.Hockeyists)
  36.                 {
  37.                     if (!hockeyist.IsTeammate)
  38.                     {
  39.                         OpponentHockeyists.Add(hockeyist);
  40.                     }
  41.                 }
  42.                 foreach (Hockeyist opponentHockeyist in OpponentHockeyists)
  43.                 {
  44.                     if (opponentHockeyist.Id == world.Puck.OwnerHockeyistId) continue;
  45.                     linesToBlock.Add(new Line()
  46.                         {
  47.                             A = new Point {X = world.Puck.X, Y = world.Puck.Y},
  48.                             B = new Point
  49.                                 {
  50.                                     X = opponentHockeyist.X,
  51.                                     Y = opponentHockeyist.Y
  52.                                 },
  53.                             LineType = LineType.PassLine
  54.                         });
  55.                 }
  56.             }
  57.             else
  58.             {
  59.                 // ШАЙБУ НЕ КОНТРОЛИРУЕТ НИКТО
  60.             }
  61.         }
  62.     }
  63.  
  64.     public static class Extras
  65.     {
  66.         public static double GetPuckAngleCos(IPuckLine puckLine, Point point)
  67.         {
  68.             double a = point.DistanceTo(puckLine.OtherPoint);
  69.             double b = puckLine.PuckPoint.DistanceTo(puckLine.OtherPoint);
  70.             double c = puckLine.PuckPoint.DistanceTo(point);
  71.             return (Math.Pow(b, 2) + Math.Pow(c, 2) - Math.Pow(a, 2)) / (2 * b * c);
  72.         }
  73.         public static double GetOtherAngleCos(IPuckLine puckLine, Point point)
  74.         {
  75.             double a = puckLine.PuckPoint.DistanceTo(point);
  76.             double b = point.DistanceTo(puckLine.OtherPoint);
  77.             double c = puckLine.PuckPoint.DistanceTo(puckLine.OtherPoint);
  78.             return (Math.Pow(b, 2) + Math.Pow(c, 2) - Math.Pow(a, 2)) / (2 * b * c);
  79.         }
  80.     }
  81.  
  82.     public enum LineType
  83.     {
  84.         GoalLine,
  85.         PassLine
  86.     }
  87.  
  88.     public interface IPuckLine
  89.     {
  90.         Point PuckPoint { get; set;  }
  91.         Point OtherPoint { get; set; }
  92.     }
  93.  
  94.  
  95.     public class Line : IPuckLine
  96.     {
  97.         public Point A { get; set; }
  98.         public Point B { get; set; }
  99.         public LineType LineType { get; set; }
  100.  
  101.         public Line()
  102.         {
  103.         }
  104.  
  105.         public double GetLength()
  106.         {
  107.             return Math.Pow((Math.Pow(B.X - A.X, 2) + Math.Pow(B.Y - A.Y, 2)), 0.5);
  108.         }
  109.  
  110.         public Point PuckPoint {
  111.             get { return A; }
  112.             set { A = value; }
  113.         }
  114.         public Point OtherPoint
  115.         {
  116.             get { return B; }
  117.             set { B = value; }
  118.         }
  119.     }
  120.  
  121.     public class Point
  122.     {
  123.         public double X { get; set; }
  124.         public double Y { get; set; }
  125.  
  126.         public Point()
  127.         {
  128.         }
  129.  
  130.         public double DistanceTo(Point toPoint)
  131.         {
  132.             return Math.Pow((Math.Pow(toPoint.X - this.X, 2) + Math.Pow(toPoint.Y - this.Y, 2)), 0.5);
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement