My question is, if there is a command/function that gives me the first value for which an expression becomes false?!
For a simulation of several rounds of the game battleships(ger. Schiffe versenken) i want to place the ships. I gave my first ship a position, which is a list of entry of my game board matrix. Now I want a program that again uses my placing algorithm for a new position, which it then compares to the old position. I have tried this with the while and if functions but they either give me several valid positions or they stop when they find the first position that would be valid, but dont print that.
Edit:
(*game board*)
Matrix[i_, j_] := Alphabet[][[i]]*j;
Spielfeld = Table[Matrix[i, j], {i, 1, 10}, {j, 1, 10}];
vertikal[n_] := Module[{s, z0, position},
s = RandomInteger[{1, 10}];
z0 = RandomInteger[{1, 10 - n + 1}];
position = Table[Spielfeld[[z, s]], {z, z0, z0 + n - 1}];
Return[position];
];
horizontal[n_] := Module[{z, s0, position},
z = RandomInteger[{1, 10}];
s0 = RandomInteger[{1, 10 - n + 1}];
position = Table[Spielfeld[[z, s]], {s, s0, s0 + n - 1}];
Return[position];
];
Schlachtschiffsetzen[n_] := Module[{position},
position =
auswahl[n] = If[RandomInteger[1] == 1, vertikal[n], horizontal[n]];
Return[position];
];
Schlachtschiff = Schlachtschiffsetzen[5];
While[ContainsNone[Schlachtschiffsetzen[4], Schlachtschiff],
Print[Schlachtschiffsetzen[4]]]
(*my lastest approach to give a new position that doesnt overlap with the other position.
But I have two problems here. First it gives several valid positions and sometimes doesnt
give any when the first it generates already overlap*)
NestWhileList
$\endgroup$