gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnugo-devel] About the Gnugo API


From: Gunnar Farnebäck
Subject: Re: [gnugo-devel] About the Gnugo API
Date: Thu, 25 Sep 2008 22:04:45 +0200
User-agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724)

Jorge Timón wrote:
> Hello, is the first time i suscribe to a mailing list, so if i do
> something wrong just tell me. I'm spanish so sorry about my poor english.

It all looks fine.

> I'm not really interested in developing gnu go but it can be usefull for
> me. I'm working in a genetics algorithms based learning machine and i
> want to use GNU go to do some tests. I'll develop a computer go player
> and i need another one to play with. GNU go seems to be perfect for
> that.The aim is not to beat GNUgo but to learn with it. This is a piece
> of code as i guess i have to write it:

If at all possible I would recommend doing the communication with GNU
Go over pipes or a socket using GTP mode. In this way you don't have
to worry about the GNU Go internals and you also get the option to
trivially switch to a newer version or switch to some other GTP
compliant program.

If you need to integrate the code tightly the safest way to find the
necessary setup is to trace what GNU Go in GTP mode does in main()
until it enters gtp_main_loop(), and then emulate the behavior of
gtp_clear_board(), gtp_play(), gtp_genmove(), and a few more commands.

>
> #include "gnugo.h"
>
> #define MEMORY 2
> #define BOARDSIZE 19
> #define KOMI 5.5int calculate_heuristic(int* board, int i, int j, int
> color);
>
> //my functions
> void insert_posible_movement(int i, int j, int heuristic_value);
> void clear_movements();
> void best_movement(int *i, int *j);
>
>
> int one_game()
> {
>
> int play=2;
> int i, j;
> int board[BOARDSIZE][BOARDSIZE]; //can it be a char matrix instead of int?
> int heur;
>
> Gameinfo gameinfo;
> init_gnugo(MEMORY);
>
> gnugo_clear_board(BOARDSIZE);
> gameinfo_clear(&gameinfo, BOARDSIZE, KOMI);
> gnugo_set_komi(KOMI);
>
> while(play>0) {
>
>  //GNUgo plays with blacks
>  gnugo_genmove(&i, &j, BLACK);
>  if (gnugo_is_pass(i, j)) play--;
>  else {
>        gnugo_play_move(i, j, BLACK);
>        play=2;
>   }
>
>  //my computer plays with whites
>  gnugo_get_board(board);
>
>  heur = calculate_heuristic(board, -1, -1, WHITE);
>  insert_posible_movement(-1, -1, heur);
>  for (int a=0; a<BOARDSIZE; a++)
>      for (int b=0; b<BOARDSIZE; b++)
>          if (gnugo_is_legal(a, b, WHITE)) {
>
>              heur = calculate_heuristic(board, a, b, WHITE);
>              insert_posible_movement(a, b, heur);
>          }
>  best_movement(&i, &j);
>  if (gnugo_is_pass(i, j)) play--;
>  else {
>       gnugo_play_move(i, j, WHITE);
>       play=2;
>  }
>
> } //end while
>
>
>   return 0; /* gnugo_estimate_score(float *upper, float *lower) or
> gnugo_who_wins(int color, FILE *outfile)???? */
>
>
> } /* end one_game */
>
> my questions:
>
> 1 am i using any function in a wrong way?

I couldn't say without trying it out myself. Neither me nor anybody
else has actively worked with those functions for years.

> 2 the board is supposed to be unsigned char, but gnugo_get_board(int
> b[MAX_BOARD][MAX_BOARD]) look like this.

gnugo_get_board converts the board information from the internal 1D
array of unsigned char to a 2D array of ints. The casting is no
problem since only the values 0, 1, 2 are used.

> 3 how can i get the final scores?

By far most easily by doing GTP communication and issuing the
final_score command.

> 4 should i use gameinfo_play_move(Gameinfo *ginfo, int i, int j, int color)?

There's no particular gain in doing that and in fact I'd rather
recommend not using the gameinfo stuff at all unless you really need
it.

> 5 need i all the files of gnugo-3.6?

You need nothing from the regression directory and of course doc only
contains documentation. You don't need the subdirectories below
interface. Otherwise most of the files are needed.

But, to repeat what I said in the beginning, use GTP mode if you can.
The API functions are ill supported and as you've noticed not all that
well documented.

If you want to use GNU Go code just for handling the board logic you
can get away with using the board library, which only involves six
files in the engine directory: board.c, board.h, boardlib.c, hash.c,
hash.h, and printutils.c.

/Gunnar




reply via email to

[Prev in Thread] Current Thread [Next in Thread]