public void Think(int time) { for (int i = 0; i < time; i++) { int newX = 0; int newY = 0; ActionType action = (ActionType)(rnd.Next() % 5) + 1; switch (action) { case ActionType.Up: if (x > 0) { newX = x - 1; newY = y; } break; case ActionType.Down: if (x > 0 && x < 9) { newX = x + 1; newY = y; } break; case ActionType.Right: if (y > 0 && y < 9) { newX = x; newY = y + 1; } break; case ActionType.Left: if (y > 0) { newX = x; newY = y - 1; } break; case ActionType.Suck: if (!map.IsRubbish(x, y)) { map.dirtyDegree++; } map.ClearRubbish(x, y); break; } if (newX != 0 && newY != 0 && map.CanMove(newX, newY)) { x = newX; y = newY; map.consumedEnergy++; } Thread.Sleep(40); if (rnd.NextDouble() < 0.015) { map.AddRubbish(); } map.Print(x, y); } }
public void Think(int time) { for (int i = 0; i < time; i++) { if (map.IsRubbish(x, y)) { map.ClearRubbish(x, y); } else { int newX = 0; int newY = 0; ActionType action = (ActionType)(rnd.Next() % 4) + 1; switch (action) { case ActionType.Up: if (x > 0) { newX = x - 1; newY = y; } break; case ActionType.Down: if (x > 0 && x < 9) { newX = x + 1; newY = y; } break; case ActionType.Right: if (y > 0 && y < 9) { newX = x; newY = y + 1; } break; case ActionType.Left: if (y > 0) { newX = x; newY = y - 1; } break; } if (newX != 0 && newY != 0 && map.CanMove(newX, newY)) { x = newX; y = newY; } } // Thread.Sleep(40); if (rnd.NextDouble() < 0.2) { map.AddRubbish(); } //map.Print(x, y); } }
public void Think(int time) { for (int i = 0; i < time; i++) { if (map.IsRubbish(x1, y1)) { map.ClearRubbish(x1, y1); } else { int newX = 0; int newY = 0; do { ActionType action = (ActionType)(rnd.Next() % 4) + 1; switch (action) { case ActionType.Up: if (x1 > 0) { newX = x1 - 1; newY = y1; } break; case ActionType.Down: if (x1 > 0 && x1 < 9) { newX = x1 + 1; newY = y1; } break; case ActionType.Right: if (y1 > 0 && y1 < 9) { newX = x1; newY = y1 + 1; } break; case ActionType.Left: if (y1 > 0) { newX = x1; newY = y1 - 1; } break; } } while (newX == 0 || newY == 0 || IsPrevious(newX, newY) || map.states[newX, newY] == "!"); if (map.CanMove(newX, newY)) { x1 = newX; y1 = newY; } else { map.states[newX, newY] = "!"; } } //Thread.Sleep(40); if (rnd.NextDouble() < 0.2) { map.AddRubbish(); } //map.Print(x1, y1); } }