public void AddBunny(string name, int team, int roomId) { var bunny = new Bunny(name, team, roomId); if (!this.roomsWithBunnies.ContainsKey(roomId)) { throw new ArgumentException(); } if (team < 0 || team > 4) { throw new IndexOutOfRangeException(); } if (this.bunnies.ContainsKey(name)) { throw new ArgumentException(); } this.bunnies[name] = bunny; if (!this.roomsWithBunnies[roomId].ContainsKey(team)) { this.roomsWithBunnies[roomId][team] = new SortedSet<Bunny>(); } this.roomsWithBunnies[roomId][team].Add(bunny); if (!this.bunniesByTeam.ContainsKey(team)) { this.bunniesByTeam[team] = new SortedSet<Bunny>(); } this.bunniesByTeam[team].Add(bunny); }
public void Next(string bunnyName) { if (!this.Bunnies.ContainsKey(bunnyName)) { throw new ArgumentException("This bunny does not exist."); } Bunny bunny = this.Bunnies[bunnyName]; int oldRoom = bunny.RoomId; int newRoom = 0; newRoom = this.BunniesByRoom.Count - 1 == this.BunniesByRoom.IndexOfKey(oldRoom) ? this.BunniesByRoom.Keys.First() : this.BunniesByRoom.Keys.First(x => x > oldRoom); int team = bunny.Team; this.BunniesByRoom[oldRoom][bunny.Team].Remove(bunny); if (!this.BunniesByRoom[newRoom].ContainsKey(team)) { this.BunniesByRoom[newRoom].Add(team, new HashSet <Bunny>()); } this.BunniesByRoom[newRoom][team].Add(bunny); bunny.RoomId = newRoom; }
public void AddBunny(string name, int team, int roomId) { if (!this.rooms.ContainsKey(roomId) || this.bunniesByName.ContainsKey(name)) { throw new ArgumentException(); } if (team < MinTeamId || team > MaxTeamId) { throw new IndexOutOfRangeException(); } var bunny = new Bunny(name, team, roomId); this.rooms[roomId].Add(bunny); if (!this.bunniesByTeam.ContainsKey(team)) { this.bunniesByTeam.Add(team, new OrderedSet <Bunny>()); } this.bunniesByTeam[team].Add(bunny); this.bunniesByName.Add(name, bunny); }
public void AddBunny(string name, int team, int roomId) { if (this.Bunnies.ContainsKey(name)) { throw new ArgumentException("A bunny with the same name already exists."); } if (!this.BunniesByRoom.ContainsKey(roomId)) { throw new ArgumentException("A room with this id is not yet created."); } if (team < 0 || team > 4) { throw new IndexOutOfRangeException("Team id Should be in the range [0..4]"); } Bunny bunny = new Bunny(name, team, roomId); if (!this.BunniesByRoom[roomId].ContainsKey(team)) { this.BunniesByRoom[roomId].Add(team, new HashSet <Bunny>()); } this.BunniesByRoom[roomId][team].Add(bunny); this.Bunnies.Add(name, bunny); if (!this.BunniesByTeamId.ContainsKey(team)) { this.BunniesByTeamId.Add(team, new SortedSet <Bunny>()); } this.BunniesByTeamId[team].Add(bunny); }
public void AddBunny(string name, int team, int roomId) { if (team > 4 || team < 0) { throw new IndexOutOfRangeException(); } Bunny bunny = new Bunny(name, team, roomId); if (!this.bunnies.ContainsKey(name) && this.roomsId.Contains(roomId)) { this.bunnies.Add(name, bunny); } else { throw new ArgumentException(); } this.teams.Add(team, bunny); if (!this.rooms.ContainsKey(roomId)) { this.rooms[roomId] = new Dictionary <string, Bunny>(); } this.rooms[roomId][name] = bunny; var bunnyNameChar = name.ToCharArray(); Array.Reverse(bunnyNameChar); this.suffixDict[string.Join("", bunnyNameChar)] = bunny; }
public void AddBunny(string name, int team, int roomId) { if(!Rooms.ContainsKey(roomId)) { throw new ArgumentException("Room " + roomId + " does not exist."); } if(BunniesByName.ContainsKey(name)) { throw new ArgumentException("Bunny " + name + " already exist."); } if (!BunniesByTeam.ContainsKey(team)) { BunniesByTeam[team] = new SortedSet<Bunny>(); } if(!BunniesByRoomTeam.ContainsKey(roomId)) { BunniesByRoomTeam[roomId] = new Dictionary<int, SortedSet<Bunny>>(); } if (!BunniesByRoomTeam[roomId].ContainsKey(team)) { BunniesByRoomTeam[roomId][team] = new SortedSet<Bunny>(); } var bunny = new Bunny(name, team, roomId); Rooms[roomId].Add(bunny); BunniesByName[name] = bunny; BunniesByTeam[team].Add(bunny); BunniesByRoomTeam[roomId][team].Add(bunny); }
public IEnumerable <Bunny> ListBunniesBySuffix(string suffix) { var min = new Bunny(suffix, 0, 0); var max = new Bunny(char.MaxValue + suffix, 0, 0); return(this.bunniesBySuffix.Range(min, true, max, false)); }
public void AddBunny(string name, int team, int roomId) { if (this.bunniesByName.ContainsKey(name)) { throw new ArgumentException("Bunny with the given name already exists."); } if (!this.bunniesInTeamsByRoom.ContainsKey(roomId)) { throw new ArgumentException("Room with the given id does not exist."); } var bunny = new Bunny(name, team, roomId); if (!this.bunniesInTeamsByRoom[roomId].ContainsKey(team)) { this.bunniesInTeamsByRoom[roomId][team] = new HashSet<Bunny>(); } this.bunniesInTeamsByRoom[roomId][team].Add(bunny); this.bunniesByName[name] = bunny; if (!this.teamsBunnies.ContainsKey(team)) { this.teamsBunnies[team] = new OrderedSet<Bunny>(); } this.teamsBunnies[team].Add(bunny); string reversedName = new string(name.Reverse().ToArray()); this.bunniesOrderedReversedNames.Add(reversedName, bunny); }
public void AddBunny(string name, int team, int roomId) { if (!this.roomsById.ContainsKey(roomId) || this.bunniesByName.ContainsKey(name)) { throw new ArgumentException(string.Format( "Room with id {0} doesn't exist or bunny with name {1} already exists", roomId, name)); } if (team < 0 || 4 < team) { throw new IndexOutOfRangeException("Team must be in the range [0...4]"); } var bunny = new Bunny(name, team, roomId); this.roomsById[roomId].Add(bunny); this.bunniesByName.Add(name, bunny); if (!this.bunniesByTeam.ContainsKey(team)) { this.bunniesByTeam[team] = new SortedSet<Bunny>(); } this.bunniesByTeam[team].Add(bunny); }
public void AddBunny(string name, int team, int roomId) { if (this.bunniesByName.ContainsKey(name)) { throw new ArgumentException("Bunny with the given name already exists."); } if (!this.bunniesInTeamsByRoom.ContainsKey(roomId)) { throw new ArgumentException("Room with the given id does not exist."); } var bunny = new Bunny(name, team, roomId); if (!this.bunniesInTeamsByRoom[roomId].ContainsKey(team)) { this.bunniesInTeamsByRoom[roomId][team] = new HashSet <Bunny>(); } this.bunniesInTeamsByRoom[roomId][team].Add(bunny); this.bunniesByName[name] = bunny; if (!this.teamsBunnies.ContainsKey(team)) { this.teamsBunnies[team] = new OrderedSet <Bunny>(); } this.teamsBunnies[team].Add(bunny); string reversedName = new string(name.Reverse().ToArray()); this.bunniesOrderedReversedNames.Add(reversedName, bunny); }
private void KillBunny(Bunny bunny) { this.bunniesByName.Remove(bunny.Name); this.bunniesByTeam[bunny.Team].Remove(bunny); this.bunniesByRoomAndTeam[bunny.RoomId][bunny.Team].Remove(bunny); this.bunniesBySuffix.Remove(bunny); }
public void Detonate(string bunnyName) { if (!this.Bunnies.ContainsKey(bunnyName)) { throw new ArgumentException("This bunny does not exist."); } Bunny bunny = this.Bunnies[bunnyName]; var otherTeams = this.BunniesByRoom[bunny.RoomId].Keys.Where(x => x != bunny.Team); foreach (var otherTeam in otherTeams) { List <Bunny> otherTeamDeadBunnies = new List <Bunny>(); var bunniesByRoomOtherTeam = this.BunniesByRoom[bunny.RoomId][otherTeam]; foreach (var other in bunniesByRoomOtherTeam) { other.Health -= BunnyDetonateDamage; if (other.Health <= 0) { otherTeamDeadBunnies.Add(other); } bunny.Score = bunny.Score + otherTeamDeadBunnies.Count; } var bunniesByTeamIdOtherTeam = this.BunniesByTeamId[otherTeam]; foreach (var other in otherTeamDeadBunnies) { bunniesByTeamIdOtherTeam.Remove(other); this.Bunnies.Remove(other.Name); bunniesByRoomOtherTeam.Remove(other); } } }
public void AddBunny(string name, int team, int roomId) { if (!roomsWithTeams.ContainsKey(roomId)) { throw new ArgumentException(); } if (team < 0 || team > 4) { throw new IndexOutOfRangeException(); } if (bunniesIds.ContainsKey(name)) { throw new ArgumentException(); } Bunny bunny = new Bunny(name, team, roomId); bunniesIds[name] = bunny; if (roomsWithTeams[roomId].Count < 5) { roomsWithTeams[roomId].Add(bunny); if (!teamIds.ContainsKey(team)) { teamIds.Add(team, new OrderedBag <Bunny>()); } teamIds[team].Add(bunny); } }
public IEnumerable <Bunny> ListBunniesBySuffix(string suffix) { var low = new Bunny(suffix, 0, 0); var upper = new Bunny(char.MaxValue + suffix, 0, 0); return(this.orderedBunnies.Range(low, true, upper, true)); }
public void Detonate(string bunnyName) { if (!bunnyNames.ContainsKey(bunnyName)) { throw new ArgumentException("Bunny with this name doesn't exist!"); } Bunny detonatingBunny = bunnyNames[bunnyName]; List <Bunny> deadBunnies = new List <Bunny>(); foreach (Bunny sufferingBunny in nodesWithRoomsById[detonatingBunny.RoomId].Value.bunniesInRoom) { if (sufferingBunny == detonatingBunny || sufferingBunny.Team == detonatingBunny.Team) { continue; } sufferingBunny.Health -= 30; if (sufferingBunny.Health <= 0) { deadBunnies.Add(sufferingBunny); } } foreach (Bunny deadBunny in deadBunnies) { detonatingBunny.Score++; this.RemoveBunny(deadBunny); } }
public void AddBunny(string bunnyName, int teamId, int roomId) { if (this.bunniesByName.ContainsKey(bunnyName)) { throw new ArgumentException("Bunny already exists"); } if (!this.roomsById.Contains(roomId)) { throw new ArgumentException("Room does not exist"); } var bunny = new Bunny(bunnyName, teamId, roomId); this.bunniesByName[bunnyName] = bunny; // Add to team if (this.bunniesByTeam[teamId] == null) { this.bunniesByTeam[teamId] = new OrderedSet<Bunny>( (b1, b2) => string.Compare(b1.Name, b2.Name)); } this.bunniesByTeam[teamId].Add(bunny); // Add to room if (this.bunniesInTeamsByRoom[roomId][teamId] == null) { this.bunniesInTeamsByRoom[roomId][teamId] = new LinkedList<Bunny>(); } this.bunniesInTeamsByRoom[roomId][teamId].AddLast(bunny); // Add to suffix set this.bunniesOrderedBySuffix.Add(bunny); }
private void MoveBunnyToRoom(Bunny bunny, int currentRoomIndex, int newRoomIndex) { if (newRoomIndex == this.bunniesInTeamsByRoom.Count) { newRoomIndex = 0; } else if (newRoomIndex == -1) { newRoomIndex = this.bunniesInTeamsByRoom.Count - 1; } // Remove from current room var oldRoom = this.roomsById[currentRoomIndex]; this.bunniesInTeamsByRoom[oldRoom][bunny.Team].Remove(bunny); // Add to new room var newRoom = this.roomsById[newRoomIndex]; if (this.bunniesInTeamsByRoom[newRoom][bunny.Team] == null) { this.bunniesInTeamsByRoom[newRoom][bunny.Team] = new LinkedList <Bunny>(); } this.bunniesInTeamsByRoom[newRoom][bunny.Team].AddLast(bunny); bunny.RoomId = newRoom; }
public void AddBunny(string name, int team, int roomId) { if (team > 4 || team < 0) { throw new IndexOutOfRangeException("Not allowed team number!"); } if (bunnyNames.ContainsKey(name)) { throw new ArgumentException("Bunny with this name already exists!"); } if (!nodesWithRoomsById.ContainsKey(roomId)) { throw new ArgumentException("No room with this ID exists!"); } Bunny newBunny = new Bunny(name, team, roomId); this.BunnyCount++; bunnyNames.Add(name, newBunny); char[] charArray = name.ToCharArray(); Array.Reverse(charArray); reversedBunnyNames.Insert(new string(charArray), 0); if (!bunniesByTeam.ContainsKey(team)) { bunniesByTeam.Add(team, new SortedSet <Bunny>()); } bunniesByTeam[team].Add(newBunny); nodesWithRoomsById[roomId].Value.bunniesInRoom.Add(newBunny); }
public void AddBunny(string name, int team, int roomId) { if (!this.roomsById.ContainsKey(roomId)) { throw new ArgumentException(); } if (this.bunniesByName.ContainsKey(name)) { throw new ArgumentException(); } if (team < 0 || team > 4) { throw new IndexOutOfRangeException(); } var bunny = new Bunny(name, team, roomId); this.roomsById[roomId].Add(bunny); this.totalBunnies++; this.bunniesByName.Add(name, bunny); // add to bunniesByTeam if (this.bunniesByTeam[team] == null) { this.bunniesByTeam[team] = new SortedSet<Bunny>(); } this.bunniesByTeam[team].Add(bunny); }
public IEnumerable <Bunny> ListBunniesBySuffix(string suffix) { var low = new Bunny(suffix, 0, 0); var high = new Bunny(char.MaxValue + suffix, 0, 0); return(this.bunniesOrderedBySuffix.Range(low, true, high, false)); }
public void AddBunny(string bunnyName, int teamId, int roomId) { if (this.bunniesByName.ContainsKey(bunnyName)) { throw new ArgumentException("Bunny already exists"); } if (!this.roomsById.Contains(roomId)) { throw new ArgumentException("Room does not exist"); } var bunny = new Bunny(bunnyName, teamId, roomId); this.bunniesByName[bunnyName] = bunny; // Add to team if (this.bunniesByTeam[teamId] == null) { this.bunniesByTeam[teamId] = new OrderedSet <Bunny>( (b1, b2) => string.Compare(b1.Name, b2.Name)); } this.bunniesByTeam[teamId].Add(bunny); // Add to room if (this.bunniesInTeamsByRoom[roomId][teamId] == null) { this.bunniesInTeamsByRoom[roomId][teamId] = new LinkedList <Bunny>(); } this.bunniesInTeamsByRoom[roomId][teamId].AddLast(bunny); // Add to suffix set this.bunniesOrderedBySuffix.Add(bunny); }
public void AddBunny(string name, int team, int roomId) { var bunny = new Bunny(name, team, roomId); if (team < 0 || team > 4) { throw new IndexOutOfRangeException(); } if (this.bunnyByRoom.ContainsKey(name) || !this.roomsBunnies.ContainsKey(roomId)) { throw new ArgumentException(); } if (this.roomsBunnies[roomId][team] == null) { this.roomsBunnies[roomId][team] = new HashSet<Bunny>(); } this.bunnyByRoom.Add(name, roomId); this.roomsBunnies[roomId][team].Add(bunny); this.bunnySuffix.Add(name, bunny); if (!this.bunniesByTeam.ContainsKey(team)) { this.bunniesByTeam.Add(team, new OrderedSet<Bunny>()); this.bunniesByTeam[team].Add(bunny); } else { this.bunniesByTeam[team].Add(bunny); } }
public void AddBunny(string name, int team, int roomId) { if (this.bunnyByName.ContainsKey(name)) { throw new ArgumentException(string.Format("A bunny with the name {0} already exists.", name)); } if (!this.bunniesByRoomId.ContainsKey(roomId)) { throw new ArgumentException("The givem ID does not exist."); } if (team < 0 || team > 4) { throw new IndexOutOfRangeException("Team can only be an integer from 0 to 4."); } var newBunny = new Bunny(name, team, roomId); this.bunniesByRoomId[roomId].Add(newBunny); this.bunnyByName.Add(name, newBunny); this.orderedBunnies.Add(newBunny); if (!this.bunniesByTeam.ContainsKey(team)) { this.bunniesByTeam[team] = new OrderedSet <Bunny>((b1, b2) => b2.Name.CompareTo(b1.Name)); } this.bunniesByTeam[team].Add(newBunny); }
private void AddBunnyInRoom(int team, int roomId, Bunny newBunny) { if (this.rooms[roomId][team] == null) { this.rooms[roomId][team] = new LinkedList <Bunny>(); } this.rooms[roomId][team].AddLast(newBunny); }
public IEnumerable <Bunny> ListBunniesBySuffix(string suffix) { var minBunny = new Bunny(suffix, 0, 0); var maxBunny = new Bunny(char.MaxValue + suffix, 0, 0); var bunniesBySufix = this.bunniesBySuffix.Range(minBunny, true, maxBunny, true); return(bunniesBySufix); }
private void AddBunnyByTeam(int team, Bunny newBunny) { if (!this.teams.ContainsKey(team)) { this.teams[team] = new SortedSet <Bunny>(); } this.teams[team].Add(newBunny); }
static void Main(string[] args) { var asd = new HashSet<Bunny>(); var bunny = new Bunny("zaio", 1, 0); asd.Add(bunny); foreach (var bunny1 in asd) { bunny1.Health = 1; } }
private void RemoveBunny(Bunny bunnyToRemove) { this.nodesWithRoomsById[bunnyToRemove.RoomId].Value.bunniesInRoom.Remove(bunnyToRemove); bunnyNames.Remove(bunnyToRemove.Name); bunniesByTeam[bunnyToRemove.Team].Remove(bunnyToRemove); char[] charArray = bunnyToRemove.Name.ToCharArray(); Array.Reverse(charArray); reversedBunnyNames.Delete(new string(charArray)); this.BunnyCount--; }
static void Main(string[] args) { var asd = new HashSet <Bunny>(); var bunny = new Bunny("zaio", 1, 0); asd.Add(bunny); foreach (var bunny1 in asd) { bunny1.Health = 1; } }
public void Previous(string bunnyName) { if (!bunniesIds.ContainsKey(bunnyName)) { throw new ArgumentException(); } rooms.Sort(); bool isFoundNextRoom = false; foreach (var kvp in roomsWithTeams) { foreach (var bunny in kvp.Value) { if (bunny.Name.Equals(bunnyName)) { Bunny foundBunny = bunny; int currentRoom = kvp.Key; for (int i = 0; i < rooms.Count; i++) { int nextRoom = Int32.MinValue; if (rooms[i] == currentRoom) { if (i == 0) { nextRoom = rooms[rooms.Count - 1]; } else if (i > 0) { nextRoom = rooms[i - 1]; } roomsWithTeams[currentRoom].Remove(foundBunny); foundBunny.RoomId = nextRoom; roomsWithTeams[nextRoom].Add(foundBunny); isFoundNextRoom = true; break; } } break; } } if (isFoundNextRoom) { break; } } }
public void AddBunny(string name, int team, int roomId) { if (this.bunnies.ContainsKey(name) || !this.rooms.ContainsKey(roomId)) { throw new ArgumentException(); } var newBunny = new Bunny(name, team, roomId); this.bunnies[name] = newBunny; this.AddBunnyInRoom(team, roomId, newBunny); this.AddBunnyByTeam(team, newBunny); this.suffixBunnies.Add(newBunny); }
public int CompareTo(object obj) { Bunny other = (Bunny)obj; string x = this.Name; string y = other.Name; if (x.Length >= y.Length) { int lenDiff = x.Length - y.Length; for (int i = x.Length - 1; i >= lenDiff; i--) { if (x[i] > y[i - lenDiff]) { return(1); } if (x[i] < y[i - lenDiff]) { return(-1); } } return(this.Name.Length.CompareTo(other.Name.Length)); } else { int lenDiff = y.Length - x.Length; for (int i = y.Length - 1; i >= lenDiff; i--) { if (y[i] > x[i - lenDiff]) { return(-1); } if (y[i] < x[i - lenDiff]) { return(1); } } return(this.Name.Length.CompareTo(other.Name.Length)); } ////slower //int compare = String.Compare(String.Join("", this.Name.Reverse()), String.Join("", other.Name.Reverse()), StringComparison.Ordinal); //if (compare == 0) //{ // return this.Name.Length.CompareTo(other.Name.Length); //} //return compare; }
private void MoveBunny(Bunny bunny, int newRoomIndex) { var newRoomId = this.sortedRooms[newRoomIndex]; this.bunniesByRoomAndTeam[bunny.RoomId][bunny.Team].Remove(bunny); if (this.bunniesByRoomAndTeam[newRoomId] == null) { this.bunniesByRoomAndTeam[newRoomId] = new LinkedList <Bunny> [MAX_TEAMS_COUNT]; } if (this.bunniesByRoomAndTeam[newRoomId][bunny.Team] == null) { this.bunniesByRoomAndTeam[newRoomId][bunny.Team] = new LinkedList <Bunny>(); } this.bunniesByRoomAndTeam[newRoomId][bunny.Team].AddLast(bunny); bunny.RoomId = newRoomId; }
public void AddBunny(string name, int team, int roomId) { if (team < IdMinValue) { throw new IndexOutOfRangeException("Team Id cannot be negative."); } if (team > IdMaxValue) { throw new IndexOutOfRangeException("Team Id cannot be above 4."); } if (this.bunnyByName.ContainsKey(name)) { throw new ArgumentException(string.Format("Bunny with name {0} already exists.", name)); } if (!this.bunniesByRoomId.ContainsKey(roomId)) { throw new ArgumentException(string.Format("Room with {0} Id does not exist.", roomId)); } var bunny = new Bunny(name, team, roomId); // Add bunny by roomID if (this.bunniesByRoomId[roomId][team] == null) { this.bunniesByRoomId[roomId][team] = new SortedSet <Bunny>(); } this.bunniesByRoomId[roomId][team].Add(bunny); // Add bunny by name this.bunnyByName.Add(name, bunny); // Add bunny by teamId if (!this.bunniesByTeamId.ContainsKey(team)) { this.bunniesByTeamId.Add(team, new SortedSet <Bunny>()); } this.bunniesByTeamId[team].Add(bunny); // Add room for suffix this.bunniesBySuffix.Add(bunny); }
private void MoveBunny(string bunnyName, Bunny currentBunny, int step) { var oldIndex = this.roomsByIndex.IndexOf(currentBunny.RoomId); var newIndex = oldIndex + step; if (newIndex > this.roomsByIndex.Count - 1) { newIndex = 0; } else if (newIndex < 0) { newIndex = this.roomsByIndex.Count - 1; } this.rooms[currentBunny.RoomId][currentBunny.Team].Remove(currentBunny); var newRoom = this.roomsByIndex[newIndex]; this.AddBunnyInRoom(currentBunny.Team, newRoom, currentBunny); currentBunny.RoomId = newRoom; }
private void ReduceHealth(Bunny currentBunny, LinkedList <Bunny> killedBunnies) { for (int i = 0; i < this.rooms[currentBunny.RoomId].Length; i++) { if (i == currentBunny.Team || this.rooms[currentBunny.RoomId][i] == null) { continue; } var currentTeam = this.rooms[currentBunny.RoomId][i]; foreach (var bunny in currentTeam) { bunny.Health -= 30; if (bunny.Health <= 0) { killedBunnies.AddLast(bunny); } } } }
public void AddBunny(string name, int team, int roomId) { if (team < 0 || team > 4) { throw new IndexOutOfRangeException(); } if (!rooms.ContainsKey(roomId) || bunnies.ContainsKey(name)) { throw new ArgumentException(); } Bunny bunny = new Bunny(name, team, roomId); bunnies.Add(name, bunny); bunniesBySuffix.Add(bunny); if (!teams.ContainsKey(team)) { teams.Add(team, new OrderedSet <Bunny>((x, y) => y.Name.CompareTo(x.Name))); } teams[team].Add(bunny); rooms[roomId][team].Add(bunny); }
public void AddBunny(string name, int team, int roomId) { TeamValidator(team); if (this._bunnyByName.ContainsKey(name) || !this._bunnyByRoomByTeam.ContainsKey(roomId)) { throw new ArgumentException(); } if (!this._bunnyByTeam.ContainsKey(team)) { this._bunnyByTeam[team] = new OrderedSet <Bunny>(); } var bunny = new Bunny(name, team, roomId); this._bunnyByName.Add(name, bunny); this._bunnyByRoomByTeam[roomId][team].AddLast(bunny); this._bunnyByTeam[team].Add(bunny); this._bySuffix.Add(bunny); }
private void RemoveBunny(Bunny bunny) { BunniesByName.Remove(bunny.Name); BunniesByTeam[bunny.Team].Remove(bunny); if( 0 == BunniesByTeam.Count ) { BunniesByTeam.Remove(bunny.Team); } Rooms[bunny.RoomId].Remove(bunny); BunniesByRoomTeam[bunny.RoomId][bunny.Team].Remove(bunny); if( 0 == BunniesByRoomTeam[bunny.RoomId][bunny.Team].Count ) { BunniesByRoomTeam[bunny.RoomId].Remove(bunny.Team); } }
private bool HitBunny(Bunny hitter, Bunny bunny) { bunny.Health -= 30; if( bunny.Health <= 0 ) { hitter.Score++; return true; } return false; }
public IEnumerable<Bunny> ListBunniesBySuffix(string suffix) { var low = new Bunny(suffix, 0, 0); var high = new Bunny(char.MaxValue + suffix, 0, 0); return this.bunniesOrderedBySuffix.Range(low, true, high, false); }
private void MoveBunnyToRoom(Bunny bunny, int currentRoomIndex, int newRoomIndex) { if (newRoomIndex == this.bunniesInTeamsByRoom.Count) newRoomIndex = 0; else if (newRoomIndex == -1) newRoomIndex = this.bunniesInTeamsByRoom.Count - 1; // Remove from current room var oldRoom = this.roomsById[currentRoomIndex]; this.bunniesInTeamsByRoom[oldRoom][bunny.Team].Remove(bunny); // Add to new room var newRoom = this.roomsById[newRoomIndex]; if (this.bunniesInTeamsByRoom[newRoom][bunny.Team] == null) { this.bunniesInTeamsByRoom[newRoom][bunny.Team] = new LinkedList<Bunny>(); } this.bunniesInTeamsByRoom[newRoom][bunny.Team].AddLast(bunny); bunny.RoomId = newRoom; }
private void RemoveBunny(Bunny bunny) { this.bunniesByName.Remove(bunny.Name); this.bunniesOrderedBySuffix.Remove(bunny); this.bunniesByTeam[bunny.Team].Remove(bunny); }