Click here to Skip to main content
11,478,896 members (64,945 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: J2ME Game AI Algorithms
I am confused in the implementation of AI. I have generated all possible moves of computer's type pieces. Now I can't decide the flow. Whether I need to start a loop for the possible moves of each piece and assign score to it.... or something else is to be done.

Kindly tell me the proper flow/algorithm for this. Thanks

For piece's evaluation, I am using the following method:
public double score(int type, int aBoard[]) {
  double reds, blacks, ret=0.0;
  int loop;     
 
  for(reds=blacks=loop=0;loop<36;loop++) {
    switch(aBoard[loop]) {
    case 2: //redKingType:
      reds+=1;
    case 0://redType:
      reds+=1;
      break;
    case 3://blackKingType:
      blacks+=1;
    case 1://blackType:
      blacks+=1;
      break;
    default:
      break;
    }
  }
  switch(type) {
  case 0://redType:
    if(reds==0) {
      return 0.0;
    }
    if(blacks==0) {
      return 24.0;
    }
    ret=reds/blacks;
    if(ret>24 || ret<0) myErr("score(i,i)");
    return ret;
  case 1://blackType:
    if(reds==0) {
      return 24.0;
    }
    if(blacks==0) {
      return 0.0;
    }
    ret=blacks/reds;
    if(ret>24 || ret<0) myErr("score(i,i)");
    return ret;
  default:
    break;
  }
  return ret;
}  

Please suggest me if I need to change the evaluation function as well.
Posted 25-Jun-12 23:43pm
Edited 26-Jun-12 4:08am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I am confused in the implementation of AI. I have generated all possible moves of computer's type pieces. Now I can't decide the flow. Whether I need to start a loop for the possible moves of each piece and assign score to it.... or something else is to be done.


......... whatever you thinking you are right...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 195
1 F-ES Sitecore 170
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,865
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,059
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 19 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100