Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Com.CodeGame.CodeHockey2014.DevKit.CSharpCgdk.Model;
- namespace Com.CodeGame.CodeHockey2014.DevKit.CSharpCgdk
- {
- public sealed class MyStrategy : IStrategy
- {
- public void Move(Hockeyist self, World world, Game game, Move move)
- {
- move.SpeedUp = -1.0D;
- move.Turn = Math.PI;
- move.Action = ActionType.Strike;
- if (world.Puck.OwnerPlayerId == world.GetMyPlayer().Id)
- {
- // ШАЙБУ КОНТРОЛИРУЕТ ИГРОК
- }
- else if (world.Puck.OwnerPlayerId == world.GetOpponentPlayer().Id)
- {
- // ШАЙБУ КОНТРОЛИРУЕТ ОППОНЕНТ
- var linesToBlock = new List<Line>();
- linesToBlock.Add(new Line()
- {
- A = new Point {X = world.Puck.X, Y = world.Puck.Y},
- B = new Point
- {
- X = world.GetMyPlayer().NetFront,
- Y = world.GetMyPlayer().NetTop +
- (world.GetMyPlayer().NetTop - world.GetMyPlayer().NetBottom)/2d
- },
- LineType = LineType.GoalLine
- });
- var OpponentHockeyists = new List<Hockeyist>();
- foreach (Hockeyist hockeyist in world.Hockeyists)
- {
- if (!hockeyist.IsTeammate)
- {
- OpponentHockeyists.Add(hockeyist);
- }
- }
- foreach (Hockeyist opponentHockeyist in OpponentHockeyists)
- {
- if (opponentHockeyist.Id == world.Puck.OwnerHockeyistId) continue;
- linesToBlock.Add(new Line()
- {
- A = new Point {X = world.Puck.X, Y = world.Puck.Y},
- B = new Point
- {
- X = opponentHockeyist.X,
- Y = opponentHockeyist.Y
- },
- LineType = LineType.PassLine
- });
- }
- }
- else
- {
- // ШАЙБУ НЕ КОНТРОЛИРУЕТ НИКТО
- }
- }
- }
- public static class Extras
- {
- public static double GetPuckAngleCos(IPuckLine puckLine, Point point)
- {
- double a = point.DistanceTo(puckLine.OtherPoint);
- double b = puckLine.PuckPoint.DistanceTo(puckLine.OtherPoint);
- double c = puckLine.PuckPoint.DistanceTo(point);
- return (Math.Pow(b, 2) + Math.Pow(c, 2) - Math.Pow(a, 2)) / (2 * b * c);
- }
- public static double GetOtherAngleCos(IPuckLine puckLine, Point point)
- {
- double a = puckLine.PuckPoint.DistanceTo(point);
- double b = point.DistanceTo(puckLine.OtherPoint);
- double c = puckLine.PuckPoint.DistanceTo(puckLine.OtherPoint);
- return (Math.Pow(b, 2) + Math.Pow(c, 2) - Math.Pow(a, 2)) / (2 * b * c);
- }
- }
- public enum LineType
- {
- GoalLine,
- PassLine
- }
- public interface IPuckLine
- {
- Point PuckPoint { get; set; }
- Point OtherPoint { get; set; }
- }
- public class Line : IPuckLine
- {
- public Point A { get; set; }
- public Point B { get; set; }
- public LineType LineType { get; set; }
- public Line()
- {
- }
- public double GetLength()
- {
- return Math.Pow((Math.Pow(B.X - A.X, 2) + Math.Pow(B.Y - A.Y, 2)), 0.5);
- }
- public Point PuckPoint {
- get { return A; }
- set { A = value; }
- }
- public Point OtherPoint
- {
- get { return B; }
- set { B = value; }
- }
- }
- public class Point
- {
- public double X { get; set; }
- public double Y { get; set; }
- public Point()
- {
- }
- public double DistanceTo(Point toPoint)
- {
- return Math.Pow((Math.Pow(toPoint.X - this.X, 2) + Math.Pow(toPoint.Y - this.Y, 2)), 0.5);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement