public GameObjectState IdentifyNearest(string type) { float closestDist = float.MaxValue; GameObjectState closest = null; foreach (GameObjectState s in seenObjects.Values) { if (s.Name == tankName) { continue; } //if teammode, don't target own tanks if (teamMode && type == "Tank") { if (OnSameTeam(tankName, s.Name)) { continue; } } if (s.Type == type) { float distance = CalculateDistance(ourMostRecentState.X, ourMostRecentState.Y, s.X, s.Y); if (distance < closestDist) { closestDist = distance; closest = s; } } } return(closest); }
private void PointToNearestType(string type) { GameObjectState nearest = IdentifyNearest(type); if (nearest != null) { //var heading = GetHeading(ourMostRecentState.X, ourMostRecentState.Y, nearest.X, nearest.Y); TurnTurretToPoint(nearest.X, nearest.Y); } }
private void MoveToNearestHealth() { Console.WriteLine("MOVE TO HEALTH"); GameObjectState nearest = IdentifyNearest("HealthPickup"); if (nearest == null) { return; } TurnTankBodyToPoint(nearest.X, nearest.Y); MoveToPoint(nearest.X, nearest.Y); }
private void MoveToNearestAmmo() { Console.WriteLine("MOVE TO AMMO"); GameObjectState nearest = IdentifyNearest("AmmoPickup"); if (nearest == null) { return; } TurnTankBodyToPoint(nearest.X, nearest.Y); MoveToPoint(nearest.X, nearest.Y); }
private float CheckDistanceToNearestEnemy() { GameObjectState nearest = bot.IdentifyNearest("Tank"); if (nearest == null) { return(0); } float distance = bot.CheckDistanceTo(nearest.X, nearest.Y); return(distance); }
private void MoveToNearestEnemy() { Console.WriteLine("MOVE TO ENEMY"); GameObjectState nearest = IdentifyNearest("Tank"); if (nearest == null) { return; } TurnTankBodyToPoint(nearest.X, nearest.Y); MoveToPoint(nearest.X, nearest.Y); }
private void DecodeMessage(NetworkMessageType messageType, int payloadLength, byte[] bytes) { try { string jsonPayload = ""; if (payloadLength > 0) { var payload = new byte[payloadLength]; Array.Copy(bytes, 2, payload, 0, payloadLength); jsonPayload = Encoding.ASCII.GetString(payload); } if (messageType == NetworkMessageType.test) { Console.WriteLine("TEST ACK RECEIVED"); } if (messageType == NetworkMessageType.objectUpdate) { GameObjectState objectState = JsonConvert.DeserializeObject <GameObjectState>(jsonPayload); //Console.WriteLine("ID: " + objectState.Id + " Type: " + objectState.Type + " Name: " + objectState.Name + " ---- " + objectState.X + "," + objectState.Y + " : " + objectState.Heading + " : " + objectState.TurretHeading); if (objectState.Name == tankName) { ourMostRecentState = objectState; } } else { Console.WriteLine(messageType.ToString()); Console.WriteLine(jsonPayload); } } catch (Exception e) { Console.WriteLine("Message decode exception " + e); } }
private void DecodeMessage(NetworkMessageType messageType, int payloadLength, byte[] bytes) { string jsonPayload = ""; try { if (payloadLength > 0) { var payload = new byte[payloadLength]; Array.Copy(bytes, 2, payload, 0, payloadLength); jsonPayload = Encoding.ASCII.GetString(payload); } if (messageType == NetworkMessageType.test) { //Console.WriteLine("TEST ACK RECEIVED"); } if (messageType == NetworkMessageType.objectUpdate) { messageCount++; GameObjectState objectState = JsonConvert.DeserializeObject <GameObjectState>(jsonPayload); //Console.WriteLine("ID: " + objectState.Id + " Type: " + objectState.Type + " Name: " + objectState.Name + " ---- " + objectState.X + "," + objectState.Y + " : " + objectState.Heading + " : " + objectState.TurretHeading); if (objectState.Name == tankName) { ourMostRecentState = objectState; //Console.WriteLine("ID: " + objectState.Id + " Type: " + objectState.Type + " Name: " + objectState.Name + " ---- " + objectState.X + "," + objectState.Y + " : " + objectState.Heading + " : " + objectState.TurretHeading); } else { if (seenObjects.ContainsKey(objectState.Id)) { seenObjects[objectState.Id] = objectState; lastStateReceived[objectState.Id] = DateTime.Now; } else { seenObjects.Add(objectState.Id, objectState); if (!lastStateReceived.ContainsKey(objectState.Id)) { lastStateReceived.Add(objectState.Id, DateTime.Now); } else { lastStateReceived[objectState.Id] = DateTime.Now; } } } } if (messageType == NetworkMessageType.kill) { unbankedPoints++; Console.WriteLine("KILL CONFIRMED"); } if (messageType == NetworkMessageType.snitchPickup) { snitchCarrier = JsonConvert.DeserializeObject <Tank>(jsonPayload); Console.WriteLine("SNITCH CARRIER DETECTED"); } if (messageType == NetworkMessageType.enteredGoal) { botStateMachine.TransitionTo(TurretBehaviour.findTarget); botStateMachine.TransitionTo(MoveBehaviour.moveToRandomPoint); unbankedPoints = 0; } } catch (Exception e) { Console.WriteLine("Message decode exception " + e); Console.WriteLine("Messaage Type: " + messageType.ToString()); Console.WriteLine("Payload Length: " + payloadLength); Console.WriteLine("Message Length: " + bytes.Length); Console.WriteLine(jsonPayload); } }