예제 #1
0
 public Point GetNextPoint()
 {
     Point head = pList.Last();
     Point nextPoint = new Point(head);
     nextPoint.Move(1, direction);
     return nextPoint;
 }
예제 #2
0
        public Snake(Point tail, int lenght, Direction _direction)
        {
            direction = _direction;
            pList = new List<Point>();

            for (int i = 0; i < lenght; i++ )
            {
                Point p = new Point(tail);
                p.Move(i, direction);
                pList.Add(p);
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var point = new Point(1, 2);
            var point2 = point.Clone() as Point;
            point.Move(2, 3);
            point.Print();
            point2.Print();

            var personWithChildren = new PersonWithChildren("John", "Doe");
            Console.WriteLine(personWithChildren.Name);
            personWithChildren.Children.Add(new PersonWithChildren("John", "Little"));
            Console.WriteLine(personWithChildren["John Little"].Name);
        }
예제 #4
0
파일: Game.cs 프로젝트: pakrym/tripplet
        /// <summary>
        /// Checks if one of the players won
        /// </summary>
        /// <returns>playerId if someone won, -1 if no one did</returns>
        public string CheckVictory(int x, int y, int z)
        {
            /*
             * Basic winner finding algo:
             *  1. generate all posible direction vectors ([-1,-1,-1], [-1,-1,0] ... )
             *  2. move from current position in vector direction while its posible, getting point A
             *  3. move from current position in reverse vector direction while posible, getting point B
             *  4. if distance between A and B is field size, we've got the winner!
             *
             */
            var who = Field[x, y, z];
            if (who == 0) return null;
            var ways = new[] { -1, 0, 1 };
            foreach (var wx in ways)
            {
                foreach (var wy in ways)
                {
                    foreach (var wz in ways)
                    {
                        if (wx == 0 && wy == 0 && wz == 0)
                            continue;

                        Point pa = new Point(x, y, z);

                        Point pb = new Point(x, y, z);

                        Point newA;
                        while ((newA = pa.Move(wx, wy, wz, _fieldSize)) != null
                               && Field[newA.X, newA.Y, newA.Z] == who)
                        {
                            pa = newA;
                        }

                        Point newB;
                        while ((newB = pb.Move(-wx, -wy, -wz, _fieldSize)) != null
                               && Field[newB.X, newB.Y, newB.Z] == who)
                        {
                            pb = newB;
                        }

                        if (pa.Distance(pb) == _fieldSize)
                        {
                            return Players[who - 1];
                        }

                    }
                }
            }
            return null;
        }
예제 #5
0
 private int GetPriority(RobotMap map, Point p, int rotation)
 {
     if (!map.Explored(p)) return 5;
     var t = map[p];
     if (t == MapTileResult.Goal) return 10000000;
     if (t == MapTileResult.Wall || t == MapTileResult.Robot) return 0;
     if (t == MapTileResult.ClosedDoor) return 0;
     var count = 1;
     if (!map.Explored(p.Move(rotation + 3))) count++;
     if (!map.Explored(p.Move(rotation))) count++;
     if (!map.Explored(p.Move(rotation + 1))) count++;
     return count;
 }