private Direction AimHome() { Direction tempdir = dir; int homeScent = 0, foodScent = 0, strongest = 0; for (int r = 0; r < 5; r++) { for (int c = 0; c < 5; c++) { int scentx = x + (r - 2); int scenty = y + (c - 2); if ((scentx != x && scenty != y) && (scentx != lastx && scenty != lasty)) { Toroidal(ref scentx, ref scenty); homeScent = 0; foodScent = 0; scent.Scents(scentx, scenty, ref homeScent, ref foodScent); if (homeScent > strongest) { strongest = homeScent; tempdir = Aim(scentx, scenty); } } } } return(tempdir); }
public void Display() { g.Clear(Color.Black); for (int r = 0; r < WWIDTH; r++) { for (int c = 0; c < WHEIGHT; c++) { Color scentcolor = new Color(); scentcolor = Color.Black; int home = 0, food = 0; int R, G, B; myScent.Scents(r, c, ref home, ref food); B = (home / 2 < 255 ? home / 2 : 255); G = (food / 4 < 255 ? food / 4 : 255); R = (food / 2 < 255 ? food / 2 : 255); b.SetPixel(r, c, Color.FromArgb(255, R, G, B)); } } for (int r = 0; r < WWIDTH; r++) { for (int c = 0; c < WHEIGHT; c++) { if (myWorld.field[r, c] == World.FOOD) { b.SetPixel(r, c, Color.Yellow); } if (myWorld.field[r, c] == World.POISON) { b.SetPixel(r, c, Color.Cyan); } } } if (showants.Checked) { foreach (Ant ant in myWorld.ants) { Color antcolor; if (ant.alive) { if (ant.poison > 0) { if (ant.hasFOOD) { antcolor = Color.LightPink; } else { antcolor = Color.HotPink; } } else { if (ant.hasFOOD) { antcolor = Color.Green; } else { antcolor = Color.Brown; } } } else { antcolor = Color.White; } b.SetPixel(ant.x, ant.y, antcolor); } } int dead = 0, poisoned = 0; foreach (Ant ant in myWorld.ants) { if (ant.poison > 0) { poisoned++; } if (ant.alive == false) { dead++; } } debugbox.Text += (myWorld.nestIsPoisoned ? "Nest Poisoned" : "Nest Clean") + "\r\n"; debugbox.Text += "collected: " + myWorld.collected + "\r\n"; debugbox.Text += "dead: " + dead + "\r\n"; debugbox.Text += "poisoned: " + poisoned + "\r\n"; this.Refresh(); }