private static void InitWharfs() { int wharfNum = 1; for (int i = 0; i < 32; i++) { wharf1[i] = new WharfPoint(wharfNum++); } for (int i = 0; i < 32; i++) { wharf2[i] = new WharfPoint(wharfNum++); } }
internal static int GetFreeWharfNumber(BoatType type) { int neededPositions = Utils.GetNumPositionsForBoatType(type); int retval = -1; if (type == BoatType.RowingBoat) { WharfPoint point = wharf1.Where(c => c.Type == BoatType.RowingBoat && c.Boats.Count == 1).FirstOrDefault(); if (point != null) { // We did find a spot with just one rowingboat so we can use it if (DebugMode) { LogEvent($"Check availability for {type}, offering number {point.WharfNumber}"); } return(point.WharfNumber); } // look at the other wharf as well point = wharf2.Where(c => c.Type == BoatType.RowingBoat && c.Boats.Count == 1).FirstOrDefault(); if (point != null) { // We did find a spot with just one rowingboat so we can use it if (DebugMode) { LogEvent($"Check availability for {type}, offering number {point.WharfNumber}"); } return(point.WharfNumber); } } // we didn't find a spot so we go on to find a completely empty spot. Or, this wasn't a rowingboat var freeNums = wharf1.Where(w => w.Type == BoatType.None).Select(s => s.WharfNumber).ToArray(); if (neededPositions == 1 && freeNums.Length > 0) { retval = freeNums[0]; } else { retval = freeNums.FindConsecutives(neededPositions); } if (retval == -1) // If we still didn't find a spot, move on to check wharf2 { freeNums = wharf2.Where(w => w.Type == BoatType.None).Select(s => s.WharfNumber).ToArray(); if (neededPositions == 1 && freeNums.Length > 0) { retval = freeNums[0]; } else { retval = freeNums.FindConsecutives(neededPositions); } } if (retval == -1) { LogEvent($"Check availability for {type}, no space found for this type!"); deniedBoats++; } else { if (DebugMode) { LogEvent($"Check availability for {type}, offering number {retval}"); } } return(retval); }