Mail Archives: djgpp/1997/11/03/07:44:20
Instead of using all those variables try using two dimensional array:
int array[6][6];
to check for vertical column just scan each column in the loop like that:
for (j=0; j<6; j++) {
for (i=0; i<4; i++) {
if (array[j][i] == array[j][i+1] && array[j][i+1] == array[j][i+2])
then you have a column with 3 same things
}
}
you can do similar thing with rows. For diagonal you rows you can just
easily modify it to make it work.
On 31 Oct 1997, Knut Pape wrote:
> I have just started programming with djgpp in C.
> After reading some Tutorials and Book's I'm trying myself on my first
> programm (4Gewinnt).
> Now I have a big problem. I have a board of 42 fields, variables from f1
> to f42.
>
> f7 f14 f21 f28 f35 f42
> f6 f13 f20 f27 f34 f41
> f5 f12 f19 f26 f33 f40
> f4 f11 f18 f25 f32 f39
> f3 f10 f17 f24 f31 f38
> f2 f9 f16 f23 f30 f37
> f1 f8 f15 f22 f29 f36
>
> Now the KI has to look up for deadly combinations
> (the aim of the Game is to get for coins of your own color in a line.
> Exampels: - | / \)
> and has to check all usable fields.
>
> With numbers as variables it wouldn't be very easy.
> For checking the line 8, 15, 22, 29 I would write a part like:
>
> if (1 == 1+7 & 1+7 == 1+14 & 1+22 == emty)
> {
> put Coin to 1+22 ;
> end turn = Yes ;
> }
>
> Now I only have to change 1 for checking another line.
>
>
> Qestion:
> 1.) Is there any possibility of changing a variable by adding numbers
> or something else like this ?
> [f"11+1" = f12 ?]
> [int Lcoin = 11;
> if (f"Lcoin" == ...) ?]
>
>
> Please help me with a good idea.
> I see a huge mountain of work befor me and
> I think the way I have to go at the moment (writing Functions for
> checking a combination
> and calling it over an over again for every field) could not be the
> best.
>
>
> PS: Forgive me my worse "English" I'm from Germany and I'm not verry
> good in English.
> ( Reading - Okay, but writing is another world.) ;-)
>
> PPS: I want to say thankyou to Shawn Hargreaves for Allegro, it helped
> me verry much.
>
>
> please remove this : v
> Answer to: Knut_Pape"nospamtome"@t-Online.de
>
>
,,,
(0 0)
+-------------oOO----(_)-------------------+
| Andrew Deren |
| aderen AT eecs DOT uic DOT edu |
| www.eecs.uic.edu/~aderen/ader/main.html |
+-------------------------oOO--------------+
|| ||
ooO Ooo
- Raw text -