Beispiel #1
0
static void manual_move( char **last, char *dice )
{
  const char *p = strtok_r( NULL, DELIM, last );
  unsigned int move;
  
  move = CSA2Internal( p );
  if( move == MOVE_NULL )
    {
      out(" Invalid Move\n");
      return;
    }

  if( is_mated() == 1 ) history_dice( 0 );
  else {
    if( dice == NULL || strcmp( dice, "1" ) < 0 || strcmp( dice, "6" ) > 0 )
      {
	out(" Invalid Number\n");
	return;
      }
    history_dice( atoi( dice ) );
  }

  char str_move[8];
  str_CSA_move( str_move, move );
  out("%s\n", str_move);
  MAKE_MOVE( move );
  out_position();

}
Beispiel #2
0
Datei: ai.c Projekt: ejrh/ejrh
int generate_all_moves(DECKP hand, MOVE *moves)
{
    int i, j;
    int num = 0;
    
    moves[num++] = MOVE_PASS;
    
    for (i = 0; i < DECK_SIZE; i++)
    {
        if (i == JOKER_VALUE && hand[i] > 0)
            moves[num++] = MOVE_JOKER;
        else
            for (j = 1; j <= hand[i]; j++)
                moves[num++] = MAKE_MOVE(i,j );
    }
    
    return num;
}
static move_t simple_move_func(const reversi_board_t *game, int player) {
    int max = -BOARD_SIZE*BOARD_SIZE;
    int count = 0;
    int row, col;
    int r;
    for(row=0; row<BOARD_SIZE; row++) {
        for(col=0; col<BOARD_SIZE; col++) {
            int v = reversi_sim_move2(game,row,col,player);
            if(v>max) {
                max = v;
                count = 1;
            }
            else if(v==max) {
                count ++;
            }
        }
    }

    if(!count) return MOVE_INVALID;

    /* chose one of the moves which scores highest */
    r = rb->rand()%count;
    row = 0;
    col = 0;
    while(true) {
        if(reversi_sim_move2(game, row, col, player)==max) {
            r--;
            if(r<0) {
                return MAKE_MOVE(row,col,player);
            }
        }
        col ++;
        if(col==BOARD_SIZE) {
            col = 0;
            row ++;
            if(row==BOARD_SIZE) {
                row = 0;
            }
        }
    }
}
Beispiel #4
0
Datei: ai.c Projekt: ejrh/ejrh
void test(void)
{
    GAME game;
    MOVE moves[MAX_MOVES];
    int vector[MAX_PLAYERS];
    int num_moves;
    int i;
    MOVE chosen_move;
    clock_t start_time, end_time;
    int centiseconds, rate;

    printf("Rankoids AI test\n");

    clear_transposition_table();
    init_stack(&game_stack, 100*sizeof(GAME));

    initialise_game(&game);
    game.num_players = 3;
    game.players[0].hand[0] = 1;
    game.players[0].hand[1] = 3;
    game.players[0].hand[3] = 2;
    game.players[1].hand[4] = 1;
    game.players[0].hand[6] = 4;
    game.players[0].hand[7] = 3;
    game.players[0].hand[10] = 2;
    game.players[0].hand[JOKER_VALUE] = 1;
    game.players[1].hand[1] = 1;
    game.players[1].hand[2] = 3;
    game.players[1].hand[3] = 1;
    game.players[1].hand[4] = 1;
    game.players[1].hand[5] = 1;
    game.players[1].hand[9] = 3;
    game.players[1].hand[12] = 1;
    game.players[1].hand[5] = 2;
    game.players[2].hand[0] = 3;
    game.players[2].hand[2] = 1;
    game.players[2].hand[3] = 1;
    game.players[1].hand[4] = 2;
    game.players[2].hand[5] = 2;
    game.players[2].hand[9] = 1;
    game.players[2].hand[11] = 4;
    game.current_player = 0;
    game.pile_owner = 0;

    printf("Current game:\n");
    print_game(&game);

    printf("All moves for player 1:\n");
    num_moves = generate_all_moves(game.players[0].hand, moves);
    for (i = 0; i < num_moves; i++)
        print_move(moves[i]);
    printf("\n");

    evaluate_game_immediate(&game, vector);
    printf("Game vector is: [%d,%d,%d]\n", vector[0], vector[1], vector[2]);

    printf("All valid moves for player 1:\n");
    num_moves = generate_valid_moves(&game, moves);
    for (i = 0; i < num_moves; i++)
        print_move(moves[i]);
    printf("\n");

    chosen_move = MAKE_MOVE(3, 2);
    printf("Apply move ");
    print_move(chosen_move);
    printf(", game is:\n");
    apply_move(&game, chosen_move);
    print_game(&game);

    evaluate_game_immediate(&game, vector);
    printf("Game vector is: [%d,%d,%d]\n", vector[0], vector[1], vector[2]);

    printf("All valid moves for player 2:\n");
    num_moves = generate_valid_moves(&game, moves);
    for (i = 0; i < num_moves; i++)
    {
        print_move(moves[i]);
        clear_transposition_table();
        evaluate_move(&game, moves[i], vector, parameters.depth);
        printf(", with vector [%d,%d,%d]\n", vector[0], vector[1], vector[2]);
    }

    node_count = 0;
    clear_transposition_table();

    start_time = clock();
    chosen_move = choose_move(&game, vector, parameters.depth+5);
    end_time = clock();
    centiseconds = (end_time - start_time)*100 / CLOCKS_PER_SEC;
    if (centiseconds != 0)
    {
        rate = (int) (100.0*node_count/centiseconds);
    }
    else
    {
        rate = 0;
    }
    printf("%d nodes examined (%d hits), time was: %0.2f seconds, rate is: %d nodes/sec\n", node_count, hit_count, centiseconds/100.0, rate);
    printf("Chosen move was:");
    print_move(chosen_move);
    printf(", with vector [%d,%d,%d]\n", vector[0], vector[1], vector[2]);

    free_stack(&game_stack);
}