public AICoordenada AICoordinate() { AICoordenada tiro = new AICoordenada(); //si el tiro anterior no fue efectivo y no estoy hundiendo ningun barco if (lasthit == false && sinking == false) { tiro = CoordenadasRandom(); } else { //si el ultimo tiro dio en el blanco tomo sus coordenadas if (continuedShots != 0) { lastEfectiveShot = shootlist[shootlist.Count - 1]; } int x = lastEfectiveShot.x; int y = lastEfectiveShot.y; if (FiltradoCoordenadas(x, y, ref tiro) == false) { tiro = CoordenadasRandom(); sinking = false; } } shootlist.Add(tiro); return(tiro); }
AICoordenada CoordenadasRandom() { AICoordenada tiro = new AICoordenada(); int x, y; x = Randomizer.Next(10); y = Randomizer.Next(15); int cheat = Randomizer.Next(6); if (cheat == 0) { while (game.GetCoordenada(x, y, 0) == 7 || game.GetCoordenada(x, y, 0) == 0 || game.GetCoordenada(x, y, 0) == 9) { x = Randomizer.Next(10); y = Randomizer.Next(15); } } else { while (game.GetCoordenada(x, y, 0) == 7 || this.Hole(x, y) == true || game.GetCoordenada(x, y, 0) == 9 || this.Side(x, y) == true) { x = Randomizer.Next(10); y = Randomizer.Next(15); } } tiro.x = x; tiro.y = y; return(tiro); }
public void Reset() { shootlist.Clear(); lastEfectiveShot = new AICoordenada(); continuedShots = 0; lasthit = false; sinking = false; }
public AI(Game Juego) { this.game = Juego; for (int i = 0; i < around.Length; i++) { around[i] = new AICoordenada(); } }
bool ChooseAnyCoordenada(ref int x, ref int y, ref AICoordenada tiro) { //escoje cualquier coordenada alrededor de un punto int j = this.Randomizer.Next(4); while (around[j].value == 7 || around[j].value == 9 || around[j].value == 10) { j = this.Randomizer.Next(4); } tiro.x = around[j].x; tiro.y = around[j].y; return(true); }
bool FiltradoCoordenadas(int x, int y, ref AICoordenada tiro) { bool found = false; //tomo las coordenadas alrededor del punto this.Around(x, y); //busco si hay algun lugar para disparar foreach (AICoordenada item in around) { if (item.value != 7 && item.value != 9 && item.value != 10) { found = true; break; } } //si hay un lugar if (found) { int shotcount = 0; //busco si alrededor ya hay un disparo efectivo foreach (var item in around) { if (item.value == 9) { shotcount++; } } //si lo hay busco su correspondiente(der-izqda , arriba-abajo) if (shotcount == 1) { return(ChooseCorrespondiente(ref tiro)); } //si no escojo cualquiera else { if (shotcount == 2) { return(false); } ChooseAnyCoordenada(ref x, ref y, ref tiro); return(true); } } //si no retorno false else { return(false); } }
bool ChooseCorrespondiente(ref AICoordenada tiro) { int sign = 2; bool found = false; for (int i = 0; i < around.Length; i++) { if (i == 2) { sign *= -1; } if (around[i].value == 9 && (around[i + sign].value != 7 && around[i + sign].value != 10)) { tiro.x = around[i + sign].x; tiro.y = around[i + sign].y; found = true; break; } } return(found); }