private void MovedOrRefresh(Player player, SeenRoom room, RoomDisplayCommand command, Direction?direction) { if (player.RoomDetectionState == RoomDetectionState.HaveMatch && command == RoomDisplayCommand.Move && direction != null) { // user is moving, verify that the new room we are in is in fact what we think it is. VerifyNewRoom(player.LastSeenRoom, direction.Value, room, player); } else { // first find a potential match for the room. FindPotentialRoomMatch(room, player); if (room.PotentialMatches.Count == 1) { // we found a definite match, simply set the current room and be done with it. SetCurrentRoom(RoomDetectionState.HaveMatch, room, player); } else if (room.PotentialMatches.Count == 0) { // found a room that we have no idea where it is, so we're officially lost. SetCurrentRoom(RoomDetectionState.NoClue, null, player); } else { if (player.RoomDetectionState == RoomDetectionState.HaveMatches && direction != null) { player.LastSeenRoom.AdjacentRooms[(int)direction] = room; SetCurrentRoom(RoomDetectionState.HaveMatches, room, player); CalculateRoomWeb(player); } else if (command == RoomDisplayCommand.Refresh && player.RoomDetectionState == RoomDetectionState.HaveMatch && room.HasMatch(player.LastSeenRoom.Match.RoomNumber)) { // player refreshed, so if we had a match don't overwrite it with an ambiguity. return; } else if (player.RoomDetectionState == RoomDetectionState.HaveMatch && command == RoomDisplayCommand.Move && direction == null) { // We couldn't tell what direction the user moved, so look at the adjacent rooms and see if there's a single match. var adjacentRooms = player.LastSeenRoom.Match.GetAdjacentRoomNumbers(); var narrowedList = room.PotentialMatches.Where(p => adjacentRooms.Any(a => p.RoomNumber == a)); if (narrowedList.Count() == 1) { room.PotentialMatches.RemoveAll(x => x.RoomNumber != narrowedList.First().RoomNumber); // found a definite match, let's assume the user moved there. SetCurrentRoom(RoomDetectionState.HaveMatch, room, player); return; } } else { SetCurrentRoom(RoomDetectionState.HaveMatches, room, player); } } } }