//每次进行计算的步骤 void A1_TickOnce(A1Thread th) { if (th.CurrentStep1 == A1Step.GetNotVisitedRoom) { if (NotVisitedRooms.Count == 0) { //结束生成 UITimer.Stop(); Restart(); return; } int idx = RandGen.Next(0, NotVisitedRooms.Count); idx = 0; th.CurrentStepRoom = NotVisitedRooms[idx]; th.CurrentStepRoom._visited = true; NotVisitedRooms.Remove(th.CurrentStepRoom); th.LastStepRooms.Clear(); th.LastStepRooms.Add(th.CurrentStepRoom); th.CurrentStep1 = A1Step.VisitNextRoom; } if (!A1_VisitNextRoom(th)) { th.CurrentStep1 = A1Step.GetNotVisitedRoom; } }
void A1Reset() { for (int i = 0; i < ths.Length; i++) { ths[i] = new A1Thread(); } }
bool A1_VisitNextRoom(A1Thread th) { int doorid = RandGen.Next(0, 4); Room room = null; bool validRoom = false; for (int i = 0; i < 4; i++) { room = GetRoomByDoor(th.CurrentStepRoom, doorid); if (null == room || th.LastStepRooms.Contains(room)) { doorid = (doorid + 1) & 3; } else { validRoom = true; break; } } if (!validRoom) { return(false); } OpenRoomDoor(th.CurrentStepRoom, doorid); if (room._visited) { return(false); } room._visited = true; th.CurrentStepRoom = room; th.LastStepRooms.Add(th.CurrentStepRoom); NotVisitedRooms.Remove(th.CurrentStepRoom); return(true); }