I'm making a checkers game and i don't know whats wrong with it.

This is a discussion on I'm making a checkers game and i don't know whats wrong with it. within the C Programming forums, part of the General Programming Boards category; So I am making a checkers game and I am still pretty new to c so can you tell me ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    16

    I'm making a checkers game and i don't know whats wrong with it.

    So I am making a checkers game and I am still pretty new to c so can you tell me whats wrong with this player move function.
    If it would help i can paste the hole thing if you want.
    Code:
    int PLAYER_MOVE()
    {
      int oldnum,newnum,k,l;
      char old,new;
      printf( "Enter current and next location your checker>>" );
      scanf( " %d%c%d%c", &oldnum, &old, &newnum, &new );
      switch ( old ) {
       case 'a':
        k=0;
       case 'b':
        k=0;
       case 'c':
        k=1;
       case 'd':
        k=1;
       case 'e':
        k=2;
       case 'f':
        k=2;
       case 'g':
        k=3;
       case 'h':
        k=3;
      }
      switch ( new ) {
       case 'a':
        l=0;
       case 'b':
        l=0;
       case 'c':
        l=1;
       case 'd':
        l=1;
       case 'e':
        l=2;
       case 'f':
        l=2;
       case 'g':
        l=3;
       case 'h':
        l=3;
      }
      int t;
      while( t == 0 ) {
       if ( BOARD[oldnum][k].PLAYER_THAT_OWNS == '1' ) {
        if ( ( oldnum - newnum == 1 ) || ( ( BOARD[oldnum][k].RANK == 'k' ) && ( ( oldnum - newnum == 1 ) || ( newnum - oldnum == 1 ) ) ) ) {
         char theoldrankonplayer;
         theoldrankonplayer == BOARD[oldnum][k].RANK;
         BOARD[newnum][l].RANK == theoldrankonplayer;
         BOARD[newnum][l].PLAYER_THAT_OWNS == '1';
         BOARD[oldnum][k].RANK == ' ';
         BOARD[oldnum][k].PLAYER_THAT_OWNS == ' ';
         t++;
        }
       }
       else {
        printf( "Bad move!" );
       }
      }
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You're using t before it has been assigned a value:

    Code:
      int t;
      while( t == 0 ) {
    Isn't the whole while loop being skipped frequently?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    Don't create massive duplicated switch statements. First off, if it really needed to be a large switch statement then you'd put it inside a function and simply call it twice, not duplicate it.

    Secondly, the following is exactly equivalent to the first switch statement:
    Code:
    if (old >= 'a' && old <= 'h')
        k = (old - 'a') / 2;
    Also consider initialising all of your variables. Whilst this is not always necessary, it looks like you would benefit from it a lot. Consider what happens if I type in 'z'.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to make a checkers game..
    By Luminous Lizard in forum C++ Programming
    Replies: 3
    Last Post: 11-14-2011, 11:04 AM
  2. Lottery game Issue in Code...whats wrong?
    By thebridge in forum C Programming
    Replies: 6
    Last Post: 10-07-2010, 08:16 PM
  3. C++ Checkers Game
    By SnS CEO in forum C++ Programming
    Replies: 9
    Last Post: 09-07-2005, 01:21 AM
  4. Jump moves in Checkers Game
    By Reb0270 in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2004, 01:06 PM
  5. IDEA: Checkers game
    By confuted in forum Contests Board
    Replies: 0
    Last Post: 06-28-2003, 03:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21