Computer Science Canada

difficulty with a piece of code, tic-tac-toe related

Author:  Fonzie [ Wed Dec 07, 2005 3:40 am ]
Post subject:  difficulty with a piece of code, tic-tac-toe related

borland compiler

so I'm nearly done a tic tac toe game and I realize that towards the middle of the game I either inexplicably win or lose. meaning the game thinks that I or the computer has gotten 3 in a row when clearly we have not. I've looked thoroughly through the program and can't seem to find any errors (it's possible I missed them I'm friggen tired). at any rate, since I can't find an error I can only assume that the part of my program that checks to see if I or the computer has 3 in a row is faulty.

int count1;
int count2;
int count3;
int ans;
int win1;
win1=0;
count1=-1;
ans = 0;
while (count1!=4&& ans!=15){
count1+=1;
count2=-1;
while (count2!=4&& ans!=15){
count2+=1;
count3=-1;
while (count3!=4&& ans!=15){
count3+=1;
if (count1!=count2 && count2!=count3 && count1!= count3){
ans = human[count1] + human[count2] + human[count3];}

}
}
}
if (ans == 15){
win1=1;}
if (ans == 15){
win1=1;}
ans=0;
count1=-1;
while (count1!=4&& ans!=15){
count1+=1;
count2=-1;
while (count2!=4&& ans!=15){
count2+=1;
count3=-1;
while (count3!=4&& ans!=15){
count3+=1;
if (count1!=count2 && count2!=count3 && count1!= count3){
ans = computer[count1] + computer[count2] + computer[count3];}
}
}
}
if (ans == 15){
win1=2;}
return win1;
}

human and computer are both 5 place global arrays which hold the value each square that was taken has. by value I mean each square has a value that is stored in the array of the person that took the square. it looks like this. 2|9|4
7|5|3
6|1|8
so that any three in a row will add up to 15. I believed that this piece of program checked every combination of three numbers from human and computer's 5 place array. if any combination of three numbers added to 15, the game would end and it would say win or lose. Does this piece of code do what I think it does? and if not, how can I fix it so that it does?

a speedy reply would be greatly appreciated.

Author:  Fonzie [ Wed Dec 07, 2005 3:46 am ]
Post subject: 

sorry to double post I can't find edit. the whole code is a function. and

2|9|4
7|5|3
6|1|8

is a model of the tic tac toe board showing which square is given what value.

Author:  Andy [ Wed Dec 07, 2005 2:25 pm ]
Post subject: 

why are u using numbers? cant a simple character do the job? '1' for first player '2' for second player and '0' for empty

Author:  Fonzie [ Wed Dec 07, 2005 2:51 pm ]
Post subject: 

I do to represent which spaces are taken. I must of not been clear. The numbers are also stored along with an array called taken which holds something like what you've descibed. the point of the numbers is that you'll notice that any three in a row add up to 15. for example the first row 2|9|4
2+9+4=15
or the diagonal, 4,5,6 which the sum of is also 15.
this is how the program identifies when a game has been won.

Author:  wtd [ Wed Dec 07, 2005 2:57 pm ]
Post subject: 

Fonzie wrote:
I do to represent which spaces are taken. I must of not been clear. The numbers are also stored along with an array called taken which holds something like what you've descibed. the point of the numbers is that you'll notice that any three in a row add up to 15. for example the first row 2|9|4
2+9+4=15
or the diagonal, 4,5,6 which the sum of is also 15.
this is how the program identifies when a game has been won.


All of the rows and diagonals add up to 15. When was the game won? Who won it?

Author:  Fonzie [ Wed Dec 07, 2005 3:08 pm ]
Post subject: 

there are two arrays; human and computer. lets say on turn one the human picks the top right corner. human[0] is assigned the value 4. then on the computers turn it picks the middle. computer[0] is assigned value 5. then this repeats on the second turn except that instead of 0 in the square brackets, it'll be one. the code I've shown here is the part of the program that determines if any three numbers in either the array human or computer adds to 15 (this is run after every turn). if this happens on the computer array, the computer wins, if it happens on the human array the human wins.

Author:  Geminias [ Wed Dec 07, 2005 10:03 pm ]
Post subject: 

hey there. if you want help than being polite is a good way to start. Good manners include using a good use of indentation in your submitted code, that way people can actually make sense of it. And please take advantage of the syntax highlighting that this forum offers.. add the tag
c++:
before your code and
after your code.


Ex.

c++:
  code


Also, use comments instead of writing a big blurb after your code. So comment places where you use tricky logic, or anything that might not be obvious to an experienced c++ programmer.

if you re-submit your code politely i'll be glad to take a look at it.

Author:  Geminias [ Wed Dec 07, 2005 10:06 pm ]
Post subject: 

oops.. it went and did the code. i meant to show you the tags for displaying c++ code.

so here's a way i know will work.


Let x be: syntax="cpp"

[x] and then [/x] to end ur code... (actually x - the ="cpp" part) lol

Author:  Geminias [ Wed Dec 07, 2005 10:22 pm ]
Post subject: 

and i'm just curious.. do you realize that in this piece of code:


[syntax="cpp"]

count3=-1; //by the way it would be more legible written: count3 = -1;

[syntax="cpp"]

you are saying count3 is equal to negative one. NOT decrement count3 by one. you declare all kinds of variables equal to -1 in your while loops.. i'm guessing this is a mistake because it looks very reduntant to me...

can i see a full source of your tick tac toe game also?

Author:  Fonzie [ Wed Dec 07, 2005 11:00 pm ]
Post subject: 

thanks for the help all the same but I've been able to crack my errors and fix the problems. and yes I was declaring them to -1 rather than a decrement, and if it looked redundant, well, my programming practices aren't perfect yet as I only recently started c++.

As for the issue of how to post things, I will use the proper etiquette next time.

Author:  [Gandalf] [ Wed Dec 07, 2005 11:40 pm ]
Post subject: 

Just in case you want to know, to use C++ syntax highlightning you type:
c++:
code goes here

Author:  [Gandalf] [ Wed Dec 07, 2005 11:42 pm ]
Post subject: 

Argh! I made just the mistake I was trying to avoid... Sorry about that.

You type this:
[syntax="cpp"]code goes here[/syntax]

Author:  Geminias [ Thu Dec 08, 2005 5:35 pm ]
Post subject: 

i began to write a tic-tac-toe game based on your idea.. and i just can't get the check function to operate properly.

This is an example of a more succinct way of testing if the values add to 15 meaning someone has won...

small problem with it though, as for some reason the values in the array's are not adding together properly and thus not performing the check right.

maybe someone can identify what the problem is?

[syntax="cpp]
#include <iostream>
#include <stdlib.h> //for rand()

int check (int computer [], int player [],const int max);

int check (int computer[], int player[],const int max)
{
int checkC = 0, checkP = 0;


for (int i = 0 ; i <= max ; i++) //this for loop adds 3 values in the array together to see if its 15
{
checkC = computer [i % max] + computer [(i + 1) % max ] + computer [(i + 2) % max ] ;
checkP = player [i % max] + player [(i + 1) % max ] + player [(i + 2) % max ] ;

if (checkC == 15)
return (2);
else if (checkP == 15)
return (1);
checkC = 0;
checkP = 0;
}

if (max >= 4) //since the for loop could get all but one possible combo, this loop is to check for the last possibility.
{
checkC = computer [0] + computer [2] + computer [3];
checkP = player [0] + player [2] + player [3];
}
if (checkC == 15)
return (2);
else if (checkP == 15)
return (1);


return 0;
}



int main ()

{

int board [9] = {2,9,4,
7,5,3,
6,1,8};
int player [5];
int computer [5];

int choice;


for (int i = 0 ; i < 5 ; i++) //initializes everything to make sure all varables have value.
{
player [i] = 10;
computer [i] = 10;


}

for (int i = 0 ; i < 5 ; i++)
{
std::cout << "Choose your next move: " << std::endl;
std::cin >> choice;

player [i] = choice - 1;
std::cout << "Your choice was: " << choice << std::endl;
for (int s = 0 ; s <= i ; s++)
{
while ((computer [i] == 10) || (computer [i] == player [s]) )
{
computer [i] = rand() % 9;
}

}

std::cout << "Computer chooses: " << computer [i] << std::endl;

player [i] = board [choice - 1];
computer [i] = board [computer [i]];
choice = 0;


if ( i >= 2 )
choice = check(player, computer, i); //choice is equal to the value check returns. Note: Choice is used in two contexts.
if (choice != 0)
if (choice == 1)
std::cout << "YOU WIN!";
else if (choice == 2)
std::cout << "YOU LOSE!";

}
std::cout << "no one won!";
std::cin.get(); //chill when program finishes.

return 0;
}



[/syntax]

Author:  Geminias [ Thu Dec 08, 2005 5:36 pm ]
Post subject: 

p.s. not having the ability to edit is just ridiculous.

c++:

#include <iostream>
#include <stdlib.h>  //for rand()

int check (int computer [], int player [],const int max);

int check (int computer[], int player[],const int max)
{
     int checkC = 0, checkP = 0
     
       
 for (int i = 0 ; i <= max  ; i++)  //this for loop adds 3 values in the array together to see if its 15
 {
         checkC = computer [i % max] + computer [(i + 1) % max ] + computer [(i + 2) % max ]  ; 
         checkP = player   [i % max] + player   [(i + 1) % max ] + player   [(i + 2) % max ]  ;   
       
    if (checkC == 15)
      return (2);
    else if (checkP == 15)
      return (1);
checkC = 0;
checkP = 0;
  }
 
  if (max >= 4)   //since the for loop could get all but one possible combo, this loop is to check for the last possibility.
  {   
      checkC = computer [0] + computer [2] + computer [3];
      checkP = player   [0] + player   [2] + player   [3];
  }   
        if (checkC == 15)
          return (2);
        else if (checkP == 15)
          return (1);
 
   
      return 0;
}


 
int main ()

{ 
   
  int board    [9] = {2,9,4,
                     7,5,3,
                     6,1,8};
  int player   [5];
  int computer [5];
 
  int choice;
 
 
 for (int i = 0 ; i < 5 ; i++)  //initializes everything to make sure all varables have value.
 {   
     player   [i] = 10;
     computer [i] = 10;
   
   
 }     
 
 for (int i = 0 ; i < 5 ; i++)
 {
     std::cout << "Choose your next move: " << std::endl;
     std::cin  >> choice;
     
player [i] = choice - 1
     std::cout << "Your choice was: " << choice << std::endl;
   for (int s = 0 ; s <= i ; s++)
   {
      while ((computer [i] == 10) || (computer [i] == player [s]) ) 
      {
             computer [i] = rand() % 9;
      }
     
   }
   
   std::cout << "Computer chooses: " << computer [i] << std::endl;
   
player   [i] = board [choice - 1];     
computer [i] = board [computer [i]];
choice       = 0;
 
     
    if ( i >= 2 )
      choice = check(player, computer, i)//choice is equal to the value check returns.  Note: Choice is used in two contexts.
      if (choice != 0)
         if (choice == 1)
           std::cout << "YOU WIN!";
         else if (choice == 2)
           std::cout << "YOU LOSE!";
     
 }
    std::cout << "no one won!";
    std::cin.get()//chill when program finishes.
   
    return 0;
}




Author:  Fonzie [ Thu Dec 08, 2005 6:02 pm ]
Post subject: 

I believe (if you were having the same mistake I was) that the reason it doesn't add correctly is because 2 numbers can add to 15. so, lets say human[4] is 0, and human [1] is 9 and human[2] is 6. 9+6+0=15. so you have to set it so that it only checks if no value of the three numbers being checked equals 0. That's the problem that I was stuck on for hours. I think it may also be the error in your code.

Author:  Geminias [ Fri Dec 09, 2005 3:59 pm ]
Post subject: 

how can that be though, i mean... the board has 9 values from 1 to 9, no value zero.

i initialized all values to 10 to begin with and i never check past the last choice.

Author:  Fonzie [ Fri Dec 09, 2005 10:37 pm ]
Post subject: 

smart move initializing them to 10, wish I'd done that to start with. Another probelm I encounted was that the same numbers were being added. like, count1, count2, and count3 were all equal to three. This means the program thinks you have the same space three times, therefore, making you win at times when you shouldn't. Could this be the problem?

Author:  wtd [ Fri Dec 09, 2005 11:28 pm ]
Post subject: 

Geminias wrote:
p.s. not having the ability to edit is just ridiculous.

c++:

#include <iostream>
#include <stdlib.h>  //for rand()

int check (int computer [], int player [],const int max);

int check (int computer[], int player[],const int max)
{
     int checkC = 0, checkP = 0
     
       
 for (int i = 0 ; i <= max  ; i++)  //this for loop adds 3 values in the array together to see if its 15
 {
         checkC = computer [i % max] + computer [(i + 1) % max ] + computer [(i + 2) % max ]  ; 
         checkP = player   [i % max] + player   [(i + 1) % max ] + player   [(i + 2) % max ]  ;   
       
    if (checkC == 15)
      return (2);
    else if (checkP == 15)
      return (1);
checkC = 0;
checkP = 0;
  }
 
  if (max >= 4)   //since the for loop could get all but one possible combo, this loop is to check for the last possibility.
  {   
      checkC = computer [0] + computer [2] + computer [3];
      checkP = player   [0] + player   [2] + player   [3];
  }   
        if (checkC == 15)
          return (2);
        else if (checkP == 15)
          return (1);
 
   
      return 0;
}


 
int main ()

{ 
   
  int board    [9] = {2,9,4,
                     7,5,3,
                     6,1,8};
  int player   [5];
  int computer [5];
 
  int choice;
 
 
 for (int i = 0 ; i < 5 ; i++)  //initializes everything to make sure all varables have value.
 {   
     player   [i] = 10;
     computer [i] = 10;
   
   
 }     
 
 for (int i = 0 ; i < 5 ; i++)
 {
     std::cout << "Choose your next move: " << std::endl;
     std::cin  >> choice;
     
player [i] = choice - 1
     std::cout << "Your choice was: " << choice << std::endl;
   for (int s = 0 ; s <= i ; s++)
   {
      while ((computer [i] == 10) || (computer [i] == player [s]) ) 
      {
             computer [i] = rand() % 9;
      }
     
   }
   
   std::cout << "Computer chooses: " << computer [i] << std::endl;
   
player   [i] = board [choice - 1];     
computer [i] = board [computer [i]];
choice       = 0;
 
     
    if ( i >= 2 )
      choice = check(player, computer, i)//choice is equal to the value check returns.  Note: Choice is used in two contexts.
      if (choice != 0)
         if (choice == 1)
           std::cout << "YOU WIN!";
         else if (choice == 2)
           std::cout << "YOU LOSE!";
     
 }
    std::cout << "no one won!";
    std::cin.get()//chill when program finishes.
   
    return 0;
}





c++:
#include <iostream>

// *** <stdlib.h> should be <cstdlib>

// For access to rand().
#include <stdlib.h> 

// *** Redundant forward declaration.
int check (int computer [], int player [],const int max);

int check(int computer[], int player[], const int max)
{
   int checkC = 0, checkP = 0;
     
   // This for loop adds 3 values in the array together to
   // see if it's 15.
   for (int i = 0 ; i <= max; i++) 
   {
       // *** You use i % max a lot.  Why not store that
       // *** value in a variable with a meaningful name?
       checkC = computer[i % max] + computer[(i + 1) % max ] + computer[(i + 2) % max ];
       checkP = player[i % max]   + player[(i + 1) % max ]   + player[(i + 2) % max ];   
       
       if (checkC == 15)
          return 2;
       else if (checkP == 15)
          return 1;
         
       checkC = 0;
       checkP = 0;
   }
 
   // *** This is not a loop, spo why does the comment say it is?
   // Since the for loop could get all but one possible combo,
   // this loop is to check for the last possibility.
   if (max >= 4)   
   {   
      checkC = computer[0] + computer[2] + computer[3];
      checkP = player[0]   + player[2]   + player[3];
   }   
       
   if (checkC == 15)
      return 2;
   else if (checkP == 15)
      return 1;
 
   
   return 0;
}


 
int main ()
{   
   int board[9] = {2,9,4
                  ,7,5,3
                  ,6,1,8},
       player[5],
       computer [5],
       choice;
 
   // Initializes everything to make sure all varables have value.
   for (int i = 0 ; i < 5 ; i++) 
   {   
      player[i]   = 10;
      computer[i] = 10;
   }     
 
   for (int i = 0; i < 5; i++)
   {
      std::cout << "Choose your next move: " << std::endl;
      std::cin  >> choice;
     
      player[i] = choice - 1;
      std::cout << "Your choice was: " << choice << std::endl;
     
      for (int s = 0 ; s <= i ; s++)
      {
         while ((computer[i] == 10) || (computer[i] == player[s]))
         {
            computer[i] = rand() % 9;
         }
      }
   
      std::cout << "Computer chooses: " << computer[i] << std::endl;
   
      player[i]   = board[choice - 1];     
      computer[i] = board[computer[i]];
      choice      = 0;
 
      if ( i >= 2 )
         // Choice is equal to the value check returns. 
         // Note: Choice is used in two contexts.
         choice = check(player, computer, i);
       
      // *** Nesting ifs without using braces is an exceptionally
      // *** bad idea.  Is it:
      // *** if (choice != 0)
      // ***    if (choice == 1)
      // ***       std::cout << "YOU WIN!";
      // ***    else if (choice == 2)
      // ***       std::cout << "YOU LOSE!";
      // *** Or?
      // *** if (choice != 0)
      // ***    if (choice == 1)
      // ***       std::cout << "YOU WIN!";
      // *** else if (choice == 2)
      // ***    std::cout << "YOU LOSE!";
     
      if (choice != 0)
         if (choice == 1)
            std::cout << "YOU WIN!";
         else if (choice == 2)
            std::cout << "YOU LOSE!";
     
    }
   
    // *** So, after possibly printing a message about something
    // *** winning or losing, you just have a blanket statement
    // *** that no one won?
    std::cout << "no one won!";
    std::cin.get()//chill when program finishes.
   
    return 0;
}

Author:  bugzpodder [ Sat Dec 10, 2005 12:00 am ]
Post subject: 

looking at ur code briefly, I've noticed that you distinguished between a player and a computer. they are the same thing really (for example, when checking winning conditions). you should just keep them in an array together. also then you can allow the computer to go first with minimal complications.

Author:  Geminias [ Sat Dec 10, 2005 9:16 pm ]
Post subject: 

is this okay now wtd? Remark: By default if you choose 5 values it will display the message "no one won". (i'd like to make it end the program in the even that someone wins, any tips on the best way to do this?)

Also there is a bug in this program, which i know how to fix but can't spend the time to at the moment. It is the fact that both player and computer get a turn each round, so there could be a tie, and in the event of a tie, the computer would win by default.

i left your comments in there wtd, and posted some of my own (//*&*)

c++:

#include <iostream>

// *** <stdlib.h> should be <cstdlib>

// For access to rand().
#include <cstdlib> 

// *** Redundant forward declaration.  // *&* Excuse me?  You mean to say that a function prototype isn't required?
int check (int computer [], int player [],const int max);

int check(int computer[], int player[], const int max)
{
   int checkC = 0, checkP = 0;   
   // This for loop adds 3 values in the array together to
   // see if it's 15.
   for (int i = 0 ; i <= max; i++) 
   {
       // *** You use i % max a lot.  Why not store that
       // *** value in a variable with a meaningful name?
       // *&* look again, i use 'i % 4' only twice.
       
       checkC = computer[i % 4] + computer[(i + 1) % 4 ] + computer[(i + 2) % 4 ];
       checkP = player[i % 4]   + player[(i + 1) % 4 ]   + player[(i + 2) % 4 ];   
       
       if (checkC == 15)
          return 2;
       if (checkP == 15)
          return 1;
         
       checkC = 0;
       checkP = 0;
   }
 
   // *** This is not a loop, spo why does the comment say it is?
   // Since the for loop could get all but one possible combo,
   // this for loop will check the last possibility.  // *&* oops, i meant if.
   if (max >= 4)   
   {   
      checkC = computer[0] + computer[2] + computer[3];
      checkP = player[0]   + player[2]   + player[3];
   }   
       
   if (checkC == 15)
      return 2;
   if (checkP == 15)
      return 1;
 
   
   return 0;
}


 
int main ()
{   
   int board[9] = {2,9,4
                  ,7,5,3
                  ,6,1,8};
   int player[5];
   int computer[5];
   int choice;
   bool OK;
   // Initializes everything to make sure all varables have value.
   for (int i = 0 ; i < 5 ; i++) 
   {   
      player[i]   = 10;
      computer[i] = 10;
   }     
 
   for (int i = 0; i < 5; i++)
   {   
         OK = false;
       
      std::cout << "Choose your next move: " << std::endl;
      std::cin  >> choice;
     
      player[i] = choice - 1;
      std::cout << "Your choice was: " << choice << std::endl;
     
      do
      {
         computer[i] = rand() % 9;
         for (int s = 0 ; s <= i ; s++)
         {
             if  (computer[i] != player [s])
             {   
                 if (i != s)
                 {
                     if (computer[i] != computer[s])
                        OK = true;
                     else
                     {
                        OK = false;
                        break;
                     }     
                 }                                   
              else
              {
                OK = false;
                break;
              }
              }   
         }   
      }        while (OK != false);
         
      std::cout << "Computer chooses: " << computer[i] << std::endl;
   
      player[i]   = board[choice - 1];     
      computer[i] = board[computer[i]];
      choice      = 0;
 
      if ( i >= 2 )
      {   // Choice is equal to the value check returns. 
         // Note: Choice is used in two contexts.
         choice = check(computer, player, i);
       
      // *** Nesting ifs without using braces is an exceptionally
      // *** bad idea.  Is it:
      // *** if (choice != 0)
      // ***    if (choice == 1)
      // ***       std::cout << "YOU WIN!";
      // ***    else if (choice == 2)
      // ***       std::cout << "YOU LOSE!";
      // *** Or?
      // *** if (choice != 0)
      // ***    if (choice == 1)
      // ***       std::cout << "YOU WIN!";
      // *** else if (choice == 2)
      // ***    std::cout << "YOU LOSE!";
     
        if (choice != 0)
        {   
            if (choice == 1)
            {
               std::cout << "YOU WIN!";
               std::cin.ignore(1,'\n');
               std::cin.ignore();
            }
            else if (choice == 2)
            {
            std::cout << "YOU LOSE!";
            std::cin.ignore(1,'\n');
            std::cin.ignore();
            }
        }
      }
    }
   
    // *** So, after possibly printing a message about something
    // *** winning or losing, you just have a blanket statement
    // *** that no one won?  //*&* that is correct.  It's called a work in progress
    std::cout << "no one won!";
    std::cin.get()//chill when program finishes.
   
    return 0;
}

Author:  [Gandalf] [ Sat Dec 10, 2005 9:44 pm ]
Post subject: 

Quote:
Excuse me? You mean to say that a function prototype isn't required?

A "function prototype" is only required by the compiler when you put your functions after your main(). Since you are placing your other functions before main(), the forward declarations are not neccessary, hence redundant.

Author:  wtd [ Sat Dec 10, 2005 9:57 pm ]
Post subject: 

code:
        if (choice != 0)
        {   
            if (choice == 1)
            {
               std::cout << "YOU WIN!";
               std::cin.ignore(1,'\n');
               std::cin.ignore();
            }
            else if (choice == 2)
            {
            std::cout << "YOU LOSE!";
            std::cin.ignore(1,'\n');
            std::cin.ignore();
            }
        }


Why do you have nested "if"s here? If "choice" is one or two, then it most certainly isn't zero.

Author:  Geminias [ Sat Dec 10, 2005 11:33 pm ]
Post subject: 

i didn't know that actually gandalf. That is informative, and wtd i'm disappointed... you were looking for bad code that hard to actually point out something as inconsequential as that?

sometimes i like to point out the obvious in my code because it helps organize things for a person (like myself who forgets the reason he wrote a line of code 10 seconds afterward). Besides, it is certainly not a mistake, it is certainly not inefficient in terms of processing speeds (if anything wouldn't it speed up processing by a few femto seconds? I can't answer this for myself since i don't know exactly how the processor deals with if statements, but it would seem logical to me that it tests each condition one by one, until it matches a condition.

Ergo, allowing it to find a match for one condition and if the match fails ignore the rest of the conditions would save on the total amount of work done.

Am i not correct? And if i am, note that this did not in any way affect my initial decision to use this technique, i merely mention it to emphasize the utter inconsequence this matter pertains. So why wtd, would you be mentioning it? unless i'm wrong of course... (which i'm not) lol

Author:  wtd [ Sat Dec 10, 2005 11:48 pm ]
Post subject: 

Geminias wrote:
i didn't know that actually gandalf. That is informative, and wtd i'm disappointed... you were looking for bad code that hard to actually point out something as inconsequential as that?


Is it inconsequential?

Such code makes me think the program was thrown together rather than designed.

Author:  Geminias [ Sun Dec 11, 2005 11:46 am ]
Post subject: 

you draw up a design every time before you code?


maybe its bad practice, but one thing i could never do is design a relatively easy logic like this on paper when i can do it in my head and give my brain a work out. that's just me.

Author:  wtd [ Sun Dec 11, 2005 1:14 pm ]
Post subject: 

Not necessarily on paper, but I do stop and think before I start typing: what do I know about the problem?

http://www.compsci.ca/v2/viewtopic.php?p=101734#101734

Author:  Geminias [ Sun Dec 11, 2005 2:46 pm ]
Post subject: 

yeah i'd never do that, actually stop and think... lol


actually when i write code it doesnt usually just flow out in one linear blob that is flawless. Usually i have to go back and make changes and add things and subtract things, you know how it is. In this case i probably started the first if statement with (!= 0) before i made the function to return specific values according to who won. Then, when i added the other stuff in it didnt occur to me to remove the initial statement.

Personally, its like i say, you are just being overly picky in this instance.

But just so we are clear about the whole thing. No i'm not so stupid that i thought to myself "Hey first i'll check to see if its equal to zero, then i'll check to see if its equal to 1 and then 2."

No, my logic is better tuned than that. it was just something that got lost in the process as i came back and redid certain things and never had the need to remove the first line.

Author:  md [ Sun Dec 11, 2005 5:55 pm ]
Post subject: 

Geminias wrote:
yeah i'd never do that, actually stop and think... lol

actually when i write code it doesnt usually just flow out in one linear blob that is flawless. Usually i have to go back and make changes and add things and subtract things, you know how it is. In this case i probably started the first if statement with (!= 0) before i made the function to return specific values according to who won. Then, when i added the other stuff in it didnt occur to me to remove the initial statement.

Stopping and thinking is what makes someone a good programmer, as opposed to a mediocre programmer. If you don't think about what you are doing how are you ever going to tackle something as complex as say encryption, or networking, or complex graphics? Even something as simple as evaluating a function contained in a string (ie. "f(x)=x^2; f(2)") is almost impossible if you don't think about it.

After a certain point you have to plan things out or you'll just get lost and nothing will work. And it's not being "overly picky" to point out flaws, no matter how small it may be; easy flaw you don't fix is a flaw that will lead to eventual problems. Wtd is just helping to point them out to you.


*** editing posts really needs to be allowed... I had to delete my post to fix this... all because I pressed submit instead of preview by accident...

Author:  Geminias [ Sun Dec 11, 2005 8:32 pm ]
Post subject: 

cornflakes cornflakes... what is a man like me to do when he gets a response like that?? haha good lord man obviously i'm just kidding. Yeah hmm.. a programmer who can't stop and think.. hmmm.. did you not see the code i posted? You ever see a 2 year old who can't stop and think draw something like that up? I dont think i need to elaborate further...

i said that because wtd claims 'he stops and thinks' about a program which is why he'd never make a mistake like that.

and is it seriously considered a flaw? i keep hearing "pointed out flaw", what flaw? i dont see a flaw personally. dont know what you call it but its not a flaw.

Author:  wtd [ Sun Dec 11, 2005 8:36 pm ]
Post subject: 

Geminias wrote:
and is it seriously considered a flaw?


Yes it is. Any program that is more complex than it has to be to accomplish its intended purpose is flawed.

Get used to accepting constructive criticism, especially from people who know more about the subject than you do. There are lots of people who are way smarter than me, and I got to be as good as I am by listening to them, and observing how they code.

Note: complexity can have varying forms.

Author:  [Gandalf] [ Sun Dec 11, 2005 8:44 pm ]
Post subject: 

Geminias, you are confusing me further when I read this post... All I gathered was that you are apparently 2 years old Laughing.

Also, you are saying that wtd is picky? Well, he is thorough in helping you make a better program in all aspects. You... You are arguing about something which I have yet to decipher... Rolling Eyes

Author:  Geminias [ Sun Dec 11, 2005 9:42 pm ]
Post subject: 

sorry to be a pain wtd, it was just that my definition of flaw differed from yours so it seemed like you were just bored and felt like knit-picking. Okay so i updated my definition of the word "flaw" and now it all makes sense. Thanks for the tip, i would have fixed it myself had i noticed it Razz

Author:  md [ Sun Dec 11, 2005 10:02 pm ]
Post subject: 

Geminias wrote:
cornflakes cornflakes... what is a man like me to do when he gets a response like that?? haha good lord man obviously i'm just kidding. Yeah hmm.. a programmer who can't stop and think.. hmmm.. did you not see the code i posted? You ever see a 2 year old who can't stop and think draw something like that up? I dont think i need to elaborate further...

i said that because wtd claims 'he stops and thinks' about a program which is why he'd never make a mistake like that.

and is it seriously considered a flaw? i keep hearing "pointed out flaw", what flaw? i dont see a flaw personally. dont know what you call it but its not a flaw.

Either use my name or piss off. Perhaps you should smarten up too, as from the quallity of the code you posted and your well thought out response you obviously aren't much older then the two year old you got to write both for you.
[/flame]

Author:  Geminias [ Sun Dec 11, 2005 10:27 pm ]
Post subject: 

that hurts man. dont misunderstand me, i'm just trying to understand the world you know, and what you said didn't make much sense to me since i thought it was obvious i can think.

Sorry for anything i said to offend.

Author:  Dan [ Thu Jan 12, 2006 2:22 pm ]
Post subject: 

Keep the falming off the help forums please.....


: