Thread: chessly ai-thingies

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    25

    chessly ai-thingies

    heres my problem: its not working, and i dont know how to make ia, so i made...an if thingie that should work. but it doesnt. it theroreticly checks all the spaces in the vicinity of the "peice" on the board "world[10][10];" the coordinates of the peice are world[aifx][aify]; it also couts the board using loops.

    an example of board cout:
    Code:
    for ( x = 0 ; x < 10 ; x++ ){
    	    if (world[x][1] == 1)
    	    cout<<"[#]";
    	    if(world[x][1]==2)
    	    cout<<"[$]";
    	    else if (world[x][1] == 0)
    	    cout<<"[ ]";
    	}
    the if checker...
    Code:
    if(world[aifx][aify]==2){
                             if(1>1000){}
    else if(world[aifx+1][aify]==1){
    chooser=1 ;
                               }
    else if(world[aifx+2][aify]==1){
    chooser=2 ;
    }
    else if(world[aifx-1][aify]==1){
    chooser=3 ;
    }
    else if(world[aifx-2][aify]==1){
    chooser=4 ;
    }
    else if(world[aifx][aify+1]==1){
    chooser=5 ;
    }
    else if(world[aifx][aify+2]==1){
    chooser=6 ;
    }
    else if(world[aifx][aify-2]==1){
    chooser=7 ;
    }
    else if(world[aifx][aify-1]==1){
    chooser=8 ;
    }
    else if(world[aifx+1][aify+1]==1){
    chooser=9 ;
    }
    else if(world[aifx+1][aify-1]==1){
    chooser=10 ;
    }
    else if(world[aifx-1][aify-1]==1){
    chooser=11 ;
    }
    else if(world[aifx-1][aify+1]==1){
    chooser=12 ;
    }
    
    
    
    switch (chooser){
          case  1:
          aifx=aifx+1;      
          break;
                case  2:
                aifx=aifx+1;
          break;
                case 3 :
                aifx=aifx-1;
          break;
                case  4:
                aifx=aifx-1;
          break;
                case  5:
                aify=aify+1;
          break;
                case  6:
                aify=aify+1;
          break;
                case  7:
                aify=aify-1;
          break;
                case  8:
                aify=aify-1;
          break;
                case  9:
                aifx=aifx+1;
          break;
                case  10:
                aifx=aifx+1;
          break;
                case  11:
                aify=aify-1;
          break;
                case  12:
                aify=aify+1;
          break;
    
               }
    }

  2. #2
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    What do you mean by "doesn't work"? I'd compile it but I'm too lazy :
    At a glance, the switch statement of chooser could be simplified to four if statements with the "or" operator. Also, the aif(x or y)=aif(x or y)(- or +)1; could be changed to aif(x or y)(- or +)=1;

    Sorry I can't help more, but I'm in a hurry.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple space combat AI
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 01-06-2009, 12:54 AM
  2. chess ai contest
    By Raven Arkadon in forum Contests Board
    Replies: 7
    Last Post: 07-09-2005, 06:38 AM
  3. AI Contest Proposal
    By MadCow257 in forum Contests Board
    Replies: 4
    Last Post: 03-13-2005, 03:27 PM
  4. Game Design Topic #1 - AI Behavior
    By TechWins in forum Game Programming
    Replies: 13
    Last Post: 10-11-2002, 10:35 AM
  5. Technique of all board-like games?
    By Nutshell in forum Game Programming
    Replies: 28
    Last Post: 04-24-2002, 08:19 AM