Recent

Author Topic: Multiple errors in my ported code  (Read 6820 times)

konniskattz

  • New member
  • *
  • Posts: 8
Multiple errors in my ported code
« on: November 13, 2018, 03:31:35 am »
Hi, I'm trying to port a C code to Pascal. (I'm new programming with Pascal)
The ported program consist of the tic-tac-toe game.
I'm getting this error:

Free Pascal Compiler version 3.0.4 [2017/10/06] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling gato.pas
gato.pas(14,25) Error: Illegal qualifier
gato.pas(16,25) Error: Illegal qualifier
gato.pas(17,6) Error: Illegal assignment to for-loop variable "j"
gato.pas(21,4) Error: Illegal assignment to for-loop variable "i"
gato.pas(34,10) Fatal: Syntax error, ")" expected but "ordinal const" found
Fatal: Compilation aborted
Error: C:\FPC\3.0.4\bin\i386-win32\ppc386.exe returned an error exitcode

Here's my code:
Code: Pascal  [Select][+][-]
  1. program gato;
  2.  
  3. uses crt;
  4.  
  5. procedure tablero(c : array of Char);
  6. var
  7.         i, j : Integer;
  8. begin
  9.         for i := 0 to 2 do
  10.                 begin
  11.                         for j := 0 to 3 do
  12.                                 begin
  13.                                         if (j < 2) then
  14.                                                 writeln(' ', c[i][j], ' |')
  15.                                         else
  16.                                                 writeln(' ', c[i][j], ' ');
  17.                                         inc(j);
  18.                                 end;
  19.                         if (i < 2) then
  20.                                 write('\n-----------\n');
  21.                         inc(i);
  22.                 end;
  23.         writeln('\n');
  24. end;
  25.  
  26. procedure mainloop(c : array of Char);
  27. var
  28.         i : Integer = 0;
  29.         j : Integer;
  30. begin
  31.         repeat
  32.                 begin
  33.                         tablero(c);
  34.                         if (i % 2 = 0) then
  35.                                 inusr(c);
  36.                         else
  37.                                 seudoai(c);
  38.                         j := win(c);
  39.                         inc(i);
  40.                 end;
  41.         until (i <= 9 && j == 2);
  42. end;
  43.  
  44. procedure inum(c : array of Char)
  45. var
  46.         i, j : Integer;
  47.         aux : Char = '0';
  48. begin
  49.         for i := 0 to 3 do
  50.                 begin
  51.                         for j := to 3 do
  52.                                 begin
  53.                                         c[i][j] := inc(aux);
  54.                                         inc(j);
  55.                                 end;
  56.                         inc(i);
  57.                 end;
  58. end;
  59.  
  60. procedure inusr(c : array of Char);
  61. var
  62.         aux : Char;
  63.         i, j, k : Integer;
  64. begin
  65.         repeat
  66.                 begin
  67.                         repeat
  68.                                 begin
  69.                                         write('Introduce ficha: ');
  70.                                         readln(c);
  71.                                 end;
  72.                         until (aux < '1') or (aux > '9');
  73.                         k := 0;
  74.                         case aux of
  75.                                 '1':
  76.                                         i := 0;
  77.                                         j := 0;
  78.                                         if (c[i][j] = 'X') then
  79.                                                 begin
  80.                                                         k := 1;
  81.                                                         writeln('Casilla ocupada!\n');
  82.                                                 end;
  83.                                 '2':
  84.                                         i := 0;
  85.                                         j := 1;
  86.                                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  87.                                                 begin
  88.                                                         k := 1;
  89.                                                         writeln('Casilla ocupada!\n');
  90.                                                 end;
  91.                                 '3':
  92.                                         i := 0;
  93.                                         j := 2;
  94.                                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  95.                                                 begin
  96.                                                         k := 1;
  97.                                                         writeln('Casilla ocupada!\n');
  98.                                                 end;
  99.                                 '4':
  100.                                         i := 1;
  101.                                         j := 0;
  102.                                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  103.                                                 begin
  104.                                                         k := 1;
  105.                                                         writeln('Casilla ocupada!\n');
  106.                                                 end;
  107.                                 '5':
  108.                                         i := 1;
  109.                                         j := 1;
  110.                                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  111.                                                 begin
  112.                                                         k := 1;
  113.                                                         writeln('Casilla ocupada!\n');
  114.                                                 end;
  115.                                 '6':
  116.                                         i := 1;
  117.                                         j := 2;
  118.                                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  119.                                                 begin
  120.                                                         k := 1;
  121.                                                         writeln('Casilla ocupada!\n');
  122.                                                 end;
  123.                                 '7':
  124.                                         i := 2;
  125.                                         j := 0;
  126.                                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  127.                                                 begin
  128.                                                         k := 1;
  129.                                                         writeln('Casilla ocupada!\n');
  130.                                                 end;
  131.                                 '8'
  132.                                         i := 2;
  133.                                         j := 1;
  134.                                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  135.                                                 begin
  136.                                                         k := 1;
  137.                                                         writeln('Casilla ocupada!\n');
  138.                                                 end;
  139.                                 '9':
  140.                                         i := 2;
  141.                                         j := 2;
  142.                                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  143.                                                 begin
  144.                                                         k := 1;
  145.                                                         writeln('Casilla ocupada!\n');
  146.                                                 end;
  147.                         end;
  148.                 end;
  149.         until (k = 1);
  150.         c[i][j] := 'X';
  151. end;
  152.  
  153. procedure seudoai(c : array of Char);
  154. var
  155.         i, j, k : Integer;
  156. begin
  157.         randomize;
  158.         repeat
  159.                 begin
  160.                         i := rand(3);
  161.                         j := rand(3);
  162.                         k := 0;
  163.                        
  164.                         if (c[i][j] = 'X') or (c[i][j] = 'O') then
  165.                                 k := 1;
  166.                 end;
  167.         until (k = 1);
  168. end;
  169.  
  170.  
  171. function win(c : array of Char) : Integer;
  172. begin
  173.         if (c[0][0] =  'X') or (c[0][1]) = 'O') then
  174.                 begin
  175.                         if (c[0][0] = c[0][1]) and (c[0][0] = c[0][2]) then
  176.                                 if (c[0][0] = 'X') then
  177.                                         win := 0;
  178.                                 else
  179.                                         win := 1;
  180.                                         {---}
  181.                 end;
  182. end;
  183.  
  184. var
  185.         c : array [1..3, 1..3] of Char;
  186.  
  187. begin
  188.         mainloop(c);
  189. end.
  190.  
The port is not complete yet, btw. But I don't wan't to compile when I finish to port all the code because I don't what to have a ton of error, so at this way I can fix the error easily.
btw, the code my is horrible.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Multiple errors in my ported code
« Reply #1 on: November 13, 2018, 07:51:55 am »
"multiple errors" indeed.Too many to itemise and correct, in fact.
You are far better to write the whole thing in Pascal from scratch, using ideas/algorithms from the C code if it helps you.
A few points about the code:
"C" isms like the operators && (and in Pascal) and % (mod in Pascal) clearly have to go.
To both pass an array parameter, and pass it back changed in Pascal you have to declare it as
Code: Pascal  [Select][+][-]
  1. SomeRoutine(var c: TArray);
  2. begin ...end;
The "c" you declare as an "array of Char" should be a matrix.
You want something like this:
Code: [Select]
type
  TRange = 1..3;
  TCharMatrix = array[TRange, TRange] of Char;
at the start of your program, and then use TCharMatrix as the type of the array you manipulate.
The compiler will then save you from range errors like trying to access c[0][0] when c's lower indexes are both 1 (provided you enable all the debugging checks, in your project, which you definitely should).
Note that Pascal for loops increment the counter variable for you. You cannot increment it yourself.
« Last Edit: November 13, 2018, 07:54:16 am by howardpc »

Thaddy

  • Hero Member
  • *****
  • Posts: 14200
  • Probably until I exterminate Putin.
Re: Multiple errors in my ported code
« Reply #2 on: November 13, 2018, 10:41:56 am »
Additionally:
== should be =
= should be :=
% should be mod
& means binary and in Pascal just and
&& means logical and in Pascal also just (some statement or expression) and (another statement or expression);
'\n' means LineEnding so if you see that at the and of a printf it means writeln in pascal if it is not present it should be write in pascal.
So printf("\n...................\n"); becomes writeln(LineEnding, '..................'); etc....

And in Pascal, main() is just the main program:
Code: C  [Select][+][-]
  1. int main{};
equals:
Code: Pascal  [Select][+][-]
  1. program  programname;
  2. var
  3.   ....
  4. begin
  5. end.
« Last Edit: November 13, 2018, 10:49:08 am by Thaddy »
Specialize a type, not a var.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Multiple errors in my ported code
« Reply #3 on: November 13, 2018, 11:18:56 am »
FPC and delphi can not work with multiple dimensions of array as parameter in a procedure. Create a type for passing your array. use this before creating the array:
Code: Pascal  [Select][+][-]
  1. type TOpenCharArray2 = array of array of char;
  2.  
  3. var
  4. c : array [0..3, 0..3] of Char;
  5.  
  6.  
  7.  
  8. procedure tablero(var c : TOpenCharArray2);
  9. var i, j : Integer;
  10. begin
  11. for i := 0 to 2 do
  12. begin
  13.   for j := 0 to 3 do
  14.   begin
  15.     if (j < 2) then
  16.       writeln(' ', c[i,j], ' |')
  17.     else
  18.       writeln(' ', c[i,j], ' ');
  19.   end;
  20.   if (i < 2) then
  21.   write('\n-----------\n');
  22. end;
  23. writeln('\n');
  24. end;
  25.                                            
  26.  
In FPC a variable can not declared directly with an value. The rule (for this moment) is this:
Code: Pascal  [Select][+][-]
  1. var aux : char;
  2. begin
  3.   aux :=  '0';
  4. end;
  5.  
Only constants can have a value but, can not be changed.
Code: Pascal  [Select][+][-]
  1. inc(aux);
  2.  
This does not work in FPC


Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

RayoGlauco

  • Full Member
  • ***
  • Posts: 176
  • Beers: 1567
Re: Multiple errors in my ported code
« Reply #4 on: November 13, 2018, 11:41:04 am »
note: you cannot change the value of a control variable in a loop:

Code: Pascal  [Select][+][-]
  1. for j := 0 to 3 do
  2.    begin
  3.      if (j < 2) then
  4.        writeln(' ', c[i][j], ' |')
  5.      else
  6.        writeln(' ', c[i][j], ' ');
  7.      inc(j);   // can't touch this!  (error)
  8.   end;
  9.  
« Last Edit: November 13, 2018, 11:48:38 am by RayoGlauco »
To err is human, but to really mess things up, you need a computer.

Thaddy

  • Hero Member
  • *****
  • Posts: 14200
  • Probably until I exterminate Putin.
Re: Multiple errors in my ported code
« Reply #5 on: November 13, 2018, 11:59:05 am »
The inc is not necessary. It is implied by the loop.  In his case on all loops.
Specialize a type, not a var.

Thaddy

  • Hero Member
  • *****
  • Posts: 14200
  • Probably until I exterminate Putin.
Re: Multiple errors in my ported code
« Reply #6 on: November 13, 2018, 12:05:39 pm »
Code: Pascal  [Select][+][-]
  1. var aux : char;
  2. begin
  3.   aux :=  '0';
  4. end;
  5.  
Only constants can have a value but, can not be changed.
Code: Pascal  [Select][+][-]
  1. inc(aux);
  2.  
This does not work in FPC
This is simply not true because of possible  {$J+} and declaring var aux:char ='0'; is also valid code. What is true is that you can not ( easily: inc(Pinteger(@i)^) modify  a for-in loop variable.
But in this case almost everywhere a byte is meant and not a pascal char. C doesn't know byte, C calls a byte char.
Moreover: most of it should work byte or char, because a pascal char is an ordinal type and can be used for loops. inc works on all ordinals.
Summary for you:
Code: Pascal  [Select][+][-]
  1. program chartest;
  2. {$J+}
  3. var
  4.   a:char;
  5. const b:char = 'x';
  6. begin
  7.   for a := 'a' to 'd' do
  8.     writeln(a);
  9.   inc(a);
  10.   writeln(a);
  11.   inc(b);
  12.   writeln(b);
  13. end.
« Last Edit: November 13, 2018, 12:34:43 pm by Thaddy »
Specialize a type, not a var.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Multiple errors in my ported code
« Reply #7 on: November 13, 2018, 01:10:07 pm »
Okay. I was misled by thit line:
Code: Pascal  [Select][+][-]
  1. c[i,j] := inc(aux);
  2.  
project1.lpr(47,18) Error: Incompatible types: got "untyped" expected "Char"
procedure inc doe not give a value back. That is why the element can't have a value.

By the way: the array is global and doesn't have to parsed as a parameter in a procedure.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

Thaddy

  • Hero Member
  • *****
  • Posts: 14200
  • Probably until I exterminate Putin.
Re: Multiple errors in my ported code
« Reply #8 on: November 13, 2018, 01:48:21 pm »

Yes, inc()/dec() are procedure intrinsics and not functions.

Which let me to do this for you  :D :D :):
Code: Pascal  [Select][+][-]
  1. function inc(var value:integer;amount:integer = 1):integer;inline;
  2. begin
  3.   system.inc(value,amount);
  4.   Result := value;
  5. end;
  6.  
  7. function dec(var value:integer;amount:integer = 1):integer;inline;
  8. begin
  9.   system.dec(value,amount);
  10.   Result := value;
  11. end;
  12.  
BTW nerd question: did you know inc can do dec and dec can do inc? depending on signedness of the "Tordinal"?
« Last Edit: November 13, 2018, 03:34:46 pm by Thaddy »
Specialize a type, not a var.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Multiple errors in my ported code
« Reply #9 on: November 14, 2018, 12:08:06 am »
The Inc and Dec should actually be functions to be used ether way....

Such as the += does but have the Inc and Dec do this also since you can specify the amount...

so like this..

 Somevariable := Inc(SomeOtherVariable,AMount:optional);

 That looks like a good idea for an inline function...

 Just thinking out loud.
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Multiple errors in my ported code
« Reply #10 on: November 14, 2018, 12:22:10 am »
The Inc and Dec should actually be functions to be used ether way....

Such as the += does but have the Inc and Dec do this also since you can specify the amount...

so like this..

 Somevariable := Inc(SomeOtherVariable,AMount:optional);

 That looks like a good idea for an inline function...

 Just thinking out loud.

The great advantage of Inc() and Dec() is that in most architectures they can be implemented as inlines with, at most, three instructions. That would be lost if they had to deal with the (relative) complexity of actually being functions, and would do nothing that you can't do with standard "add" or "substract" operations. That, I guess, is why they are simple procedures.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Multiple errors in my ported code
« Reply #11 on: November 14, 2018, 12:27:49 am »
I was thinking in the lines of an intrinsic complier add since INC and DEC are already intrinsic.

It can perform the same as a Function or Procedure except as a function it can allow the newly resolved
value to be return as well it directly modifying it as a procedure..

 Oh Well.
The only true wisdom is knowing you know nothing

konniskattz

  • New member
  • *
  • Posts: 8
Re: Multiple errors in my ported code
« Reply #12 on: November 14, 2018, 01:33:57 am »
Okay, thanks and sorry for pissing you off.
I think it will be very difficult to portray the code, especially the way the variables are declared in Pascal.
Thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 14200
  • Probably until I exterminate Putin.
Re: Multiple errors in my ported code
« Reply #13 on: November 14, 2018, 07:37:45 am »
Okay, thanks and sorry for pissing you off.
I think it will be very difficult to portray the code, especially the way the variables are declared in Pascal.
Thanks
No it is actually quite simple if you know both languages. As you observed the languages are quite similar, only not as similar as you think.
I am quite sure that I am not the only one who got it working, we just want that you do it yourself, so you learn from it. We gave all necessary information.
If you could attach the original C code I can show you how to translate it side by side.
« Last Edit: November 14, 2018, 08:11:39 am by Thaddy »
Specialize a type, not a var.

konniskattz

  • New member
  • *
  • Posts: 8
Re: Multiple errors in my ported code
« Reply #14 on: November 15, 2018, 12:13:49 am »
Okay, thanks and sorry for pissing you off.
I think it will be very difficult to portray the code, especially the way the variables are declared in Pascal.
Thanks
No it is actually quite simple if you know both languages. As you observed the languages are quite similar, only not as similar as you think.
I am quite sure that I am not the only one who got it working, we just want that you do it yourself, so you learn from it. We gave all necessary information.
If you could attach the original C code I can show you how to translate it side by side.
Here's my original C code:
Code: C  [Select][+][-]
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. void mainloop(char c[3][3]);
  6. void inum(char c[3][3]);
  7. void tablero(char c[3][3]);
  8. void inusr(char c[3][3]);
  9. void seudoai(char c[3][3]);
  10. int win(char c[3][3]);
  11.  
  12. int main()
  13. {
  14.         char c[3][3];
  15.         mainloop(c);
  16.        
  17.         system("pause");
  18.         return 0;
  19. }
  20.  
  21. void mainloop(char c[3][3])
  22. {
  23.         int j;
  24.         int i = 0;
  25.         inum(c);
  26.        
  27.         do
  28.         {
  29.                 system("cls");
  30.                 tablero(c);
  31.                 if(i % 2 == 0)
  32.                 {
  33.                         inusr(c);
  34.                 }
  35.                 else
  36.                 {
  37.                         seudoai(c);
  38.                 }
  39.                 j = win(c);
  40.                 ++i;
  41.         }while(i <= 9 && j == 2);
  42.        
  43.        
  44.         if(j == 0)
  45.         {
  46.                 printf("Ganaste!\n\n");
  47.         }
  48.         else if(j == 1)
  49.         {
  50.                 printf("Perdiste!\n\n");
  51.         }
  52.         else
  53.         {
  54.                 printf("Empate!\n\n");
  55.         }
  56.        
  57. }
  58.  
  59. void inum(char c[3][3])
  60. {
  61.         int i, j;
  62.         char aux = '0';
  63.        
  64.         for(i = 0; i < 3; ++i)
  65.         {
  66.                 for(j = 0; j < 3; ++j)
  67.                 {
  68.                         c[i][j] = ++aux;
  69.                 }
  70.         }
  71. }
  72.  
  73. void inusr(char c[3][3])
  74. {
  75.         char aux;
  76.         int i, j, k;
  77.        
  78.         do
  79.         {
  80.                 do
  81.                 {
  82.                         printf("Introduce ficha: ");
  83.                         fflush(stdin);
  84.                         scanf("%c", &aux);
  85.                 }while(aux < '1' || aux > '9');
  86.                
  87.                 k = 0;
  88.                
  89.                 switch(aux)
  90.                 {
  91.                         case '1':{
  92.                                 i = 0;
  93.                                 j = 0;
  94.                                 if (c[i][j] == 'X')
  95.                                 {
  96.                                         k = 1;
  97.                                         printf("Casilla ocupada!\n\n");
  98.                                 }
  99.                                 break;
  100.                         }
  101.                         case '2':{
  102.                                 i = 0;
  103.                                 j = 1;
  104.                                 if (c[i][j] == 'X' || c[i][j] == 'O')
  105.                                 {
  106.                                         k = 1;
  107.                                         printf("Casilla ocupada!\n\n");
  108.                                 }
  109.                                 break;
  110.                         }
  111.                         case '3':{
  112.                                 i = 0;
  113.                                 j = 2;
  114.                                 if (c[i][j] == 'X' || c[i][j] == 'O')
  115.                                 {
  116.                                         k = 1;
  117.                                         printf("Casilla ocupada!\n\n");
  118.                                 }
  119.                                 break;
  120.                         }
  121.                         case '4':{
  122.                                 i = 1;
  123.                                 j = 0;
  124.                                 if (c[i][j] == 'X' || c[i][j] == 'O')
  125.                                 {
  126.                                         k = 1;
  127.                                         printf("Casilla ocupada!\n\n");
  128.                                 }
  129.                                 break;
  130.                         }
  131.                         case '5':{
  132.                                 i = 1;
  133.                                 j = 1;
  134.                                 if (c[i][j] == 'X' || c[i][j] == 'O')
  135.                                 {
  136.                                         k = 1;
  137.                                         printf("Casilla ocupada!\n\n");
  138.                                 }
  139.                                 break;
  140.                         }
  141.                         case '6':{
  142.                                 i = 1;
  143.                                 j = 2;
  144.                                 if (c[i][j] == 'X' || c[i][j] == 'O')
  145.                                 {
  146.                                         k = 1;
  147.                                         printf("Casilla ocupada!\n\n");
  148.                                 }
  149.                                 break;
  150.                         }
  151.                         case '7':{
  152.                                 i = 2;
  153.                                 j = 0;
  154.                                 if (c[i][j] == 'X' || c[i][j] == 'O')
  155.                                 {
  156.                                         k = 1;
  157.                                         printf("Casilla ocupada!\n\n");
  158.                                 }
  159.                                 break;
  160.                         }
  161.                         case '8':{
  162.                                 i = 2;
  163.                                 j = 1;
  164.                                 if (c[i][j] == 'X' || c[i][j] == 'O')
  165.                                 {
  166.                                         k = 1;
  167.                                         printf("Casilla ocupada!\n\n");
  168.                                 }
  169.                                 break;
  170.                         }
  171.                         case '9':{
  172.                                 i = 2;
  173.                                 j = 2;
  174.                                 if (c[i][j] == 'X' || c[i][j] == 'O')
  175.                                 {
  176.                                         k = 1;
  177.                                         printf("Casilla ocupada!\n\n");
  178.                                 }
  179.                                 break;
  180.                         }
  181.                 }
  182.         }while(k == 1);
  183.        
  184.         c[i][j] = 'X';
  185. }
  186.  
  187. void seudoai(char c[3][3])
  188. {
  189.         int i, j, k;
  190.         //char aux;
  191.         srand(time(NULL));
  192.        
  193.         do
  194.         {
  195.                 i = rand() % 3; // n rand entre 0 y 2
  196.                 j = rand() % 3;
  197.                 k = 0;
  198.                
  199.                 if(c[i][j] == 'X' || c[i][j] == 'O')
  200.                 {
  201.                         k = 1;
  202.                 }
  203.         }while(k == 1);
  204.         c[i][j] = 'O';
  205. }
  206.  
  207. void tablero(char c[3][3])
  208. {
  209.         int i, j;
  210.        
  211.         for(i = 0; i < 3; ++i)
  212.         {
  213.                 for(j = 0; j < 3; ++j) //replace ++j with ++i, and have fun!
  214.                 {
  215.                         if(j < 2)
  216.                         {
  217.                                 printf(" %c |", c[i][j]);
  218.                         }
  219.                         else
  220.                         {
  221.                                 printf(" %c ", c[i][j]);
  222.                         }
  223.                 }
  224.                 if(i < 2)
  225.                 {
  226.                         printf("\n-----------\n");
  227.                 }
  228.         }
  229.         printf("\n\n");
  230. }
  231.  
  232. int win(char c[3][3])
  233. {
  234.         if(c[0][0] == 'X' || c[0][0] == 'O')
  235.         {
  236.                 if(c[0][0] == c[0][1] && c[0][0] == c[0][2])
  237.                 {
  238.                         if(c[0][0] == 'X')
  239.                         {
  240.                                 return 0;
  241.                         }
  242.                         else
  243.                         {
  244.                                 return 1;
  245.                         } //---
  246.                 }
  247.                 else if(c[0][0] == c[1][0] && c[0][0] == c[2][0])
  248.                 {
  249.                         if(c[0][0] == 'X')
  250.                         {
  251.                                 return 0;
  252.                         }
  253.                         else
  254.                         {
  255.                                 return 1;
  256.                         }      
  257.                 }
  258.         }
  259.         if(c[1][1] == 'X' || c[1][1] == 'O')
  260.         {
  261.                 if(c[1][1] == c[0][0] && c[1][1] == c[2][2])
  262.                 {
  263.                         if(c[1][1] == 'X')
  264.                         {
  265.                                 return 0;
  266.                         }
  267.                         else
  268.                         {
  269.                                 return 1;
  270.                         }      
  271.                 }
  272.                 if(c[1][1] == c[1][0] && c[1][1] == c[1][2])
  273.                 {
  274.                         if(c[1][1] == 'X')
  275.                         {
  276.                                 return 0;
  277.                         }
  278.                         else
  279.                         {
  280.                                 return 1;
  281.                         }
  282.                 }
  283.                 if(c[1][1] == c[2][0] && c[1][1] == c[0][2])
  284.                 {
  285.                         if(c[1][1] == 'X')
  286.                         {
  287.                                 return 0;
  288.                         }
  289.                         else
  290.                         {
  291.                                 return 1;
  292.                         }
  293.                 }
  294.                 if(c[1][1] == c[0][1] && c[1][1] == c[2][1])
  295.                 {
  296.                         if(c[1][1] == 'X')
  297.                         {
  298.                                 return 0;
  299.                         }
  300.                         else
  301.                         {
  302.                                 return 1;
  303.                         }
  304.                 }
  305.         }
  306.         if(c[2][2] == 'X' || c[2][2] == 'O')
  307.         {
  308.                 if(c[2][2] == c[2][0] && c[2][1] == c[2][1])
  309.                 {
  310.                         if(c[2][2] == 'X')
  311.                         {
  312.                                 return 0;
  313.                         }
  314.                         else
  315.                         {
  316.                                 return 1;
  317.                         }      
  318.                 }
  319.                 if(c[2][2] == c[0][2] && c[2][2] == c[1][2])
  320.                 {
  321.                         if(c[2][2] == 'X')
  322.                         {
  323.                                 return 0;
  324.                         }
  325.                         else
  326.                         {
  327.                                 return 1;
  328.                         }      
  329.                 }
  330.         }
  331.         return 2;
  332. }
  333.  
  334.  
Sorry for the code strings in spanish...

 

TinyPortal © 2005-2018