public Statistics() { _playerUp = false; _playerDown = false; _playerRight = false; _playerLeft = false; _closestCoin = new ClosestTreasure(); _closestLifePack = new ClosestTreasure(); deadCount = 0; myPlayer = Map.getMap.AllTanks[Map.getMap.MyIndex]; all = Map.getMap.AllTanks; enemies = new Player[Map.getMap.NoOfPlayers - 1]; int j = 0; for (int i = 0; i < Map.getMap.NoOfPlayers; i++) { if (all[i].Coordinate != all[Map.getMap.MyIndex].Coordinate) { enemies[j] = all[i]; j++; } } }
public void setRealCostsToPath(ref ClosestTreasure treasure, bool isLifePack) { int myHealth = Map.getMap.AllTanks[Map.getMap.MyIndex].Health; switch (isLifePack) { case true: if (myHealth < 49) { treasure.Cost = treasure.Cost * 1; } else if (myHealth < 79) { treasure.Cost = treasure.Cost * 2; } else if (myHealth < 99) { treasure.Cost = treasure.Cost * 5; } else if (myHealth < 150) { treasure.Cost = treasure.Cost * 8; } else { treasure.Cost = treasure.Cost * 9; } break; case false: if (myHealth < 49) { treasure.Cost = treasure.Cost * 9; } else if (myHealth < 79) { treasure.Cost = treasure.Cost * 8; } else if (myHealth < 99) { treasure.Cost = treasure.Cost * 5; } else if (myHealth < 150) { treasure.Cost = treasure.Cost * 2; } else { treasure.Cost = treasure.Cost * 1; } break; } }
public void findBestTreasureToFollow() { if (_closestCoin.CompareTo(_closestLifePack) >= 0) { _bestToFollow = _closestCoin; Console.WriteLine("bestToFollow is the coin at: " + _closestCoin.Coordinate.X + ", " + _closestCoin.Coordinate.Y); } else { _bestToFollow = _closestLifePack; Console.WriteLine("bestToFollow is the lifepack at: " + _closestLifePack.Coordinate.X + ", " + _closestLifePack.Coordinate.Y); } }
// public void HighlightPath(Point startingPoint) public void HighlightPath(ref ClosestTreasure treasure) { // Console.WriteLine("Highlighting path to treasure point: "+treasure.Coordinate.X+", "+treasure.Coordinate.Y); /* * * Mark the path from monster to hero. * * */ // Point startingPoint = FindCode(goal); /*int pointX = startingPoint.X; * int pointY = startingPoint.Y;*/ int pointX = treasure.Coordinate.X; int pointY = treasure.Coordinate.Y; if (pointX == -1 && pointY == -1) { Console.WriteLine("inside if"); } while (true) { /* * * Look through each direction and find the square * with the lowest number of steps marked. * * */ //Point lowestPoint = Point.Empty; Point lowestPoint = new Point(0, 0); int lowest = 10000; //my test foreach (Point movePoint in ValidMoves(pointX, pointY)) { int count = _squares[movePoint.X, movePoint.Y].DistanceSteps; //Console.WriteLine("count before if "+count); if (count < lowest) { lowest = count; //Console.WriteLine("count: "+count); lowestPoint.X = movePoint.X; lowestPoint.Y = movePoint.Y; } } /* for (int i = 0; i < 4; i++) * { * int newX = points[pointX,pointY].X + _movements[i].X; * int newY = points[pointX, pointY].Y + _movements[i].Y; * * if (ValidCoordinates(newX, newY) && SquareOpen(newX, newY)) * { * int count = _squares[points[newX,newY].X, points[newX,newY].Y].DistanceSteps; * //Console.WriteLine("count before if "+count); * if (count < lowest) * { * lowest = count; * //Console.WriteLine("count: "+count); * lowestPoint.X = points[newX, newY].X; * lowestPoint.Y = points[newX, newY].Y; * } * } * }*/ //my test over if (lowest != 10000) { /* * * Mark the square as part of the path if it is the lowest * number. Set the current position as the square with * that number of steps. * * */ _squares[lowestPoint.X, lowestPoint.Y].IsPath = true; try { //path.AddFirst(points[lowestPoint.X, lowestPoint.Y]); // Console.WriteLine("checking whether treasure is null "+treasure.Cost); if (treasure == null) { Console.WriteLine("treasure is null"); } if (treasure.Path == null) { Console.WriteLine("treasure.Path is null"); } try { treasure.Path.AddFirst(points[lowestPoint.X, lowestPoint.Y]); } catch (NullReferenceException nre) { Console.WriteLine(nre.Message); treasure.Path.Clear(); //to avoid hitting obstacles. I guess it happened because I didnt clear the half added path. break; //to solve null reference problem. dont know whether this will work; } // Console.WriteLine("path highlighting "+treasure.Path.First.Value.X+" "+treasure.Path.First.Value.Y); } catch (OutOfMemoryException oome) { //Console.WriteLine(oome.Message); Console.WriteLine("oome Exception at HighlightPath"); } pointX = lowestPoint.X; pointY = lowestPoint.Y; } else { Console.WriteLine("else"); break; } // if (_squares[pointX, pointY].ContentCode == SquareContent.me) if (pointX == Map.getMap.AllTanks[Map.getMap.MyIndex].Coordinate.X && pointY == Map.getMap.AllTanks[Map.getMap.MyIndex].Coordinate.Y) { /* * * We went from monster to hero, so we're finished. * * */ //Console.WriteLine("path marked"); treasure.Path.AddLast(points[treasure.Coordinate.X, treasure.Coordinate.Y]); //Console.WriteLine("path highlighting " + treasure.Path.Last.Value.X + " " + treasure.Path.Last.Value.Y); break; } } }