Skip to content
Browse files

Sat Apr 30 21:01:44 BST 2005 Stig Brautaset <stig@brautaset.org>

  * hack-n-slash; moth cli version can play

    M ./config/config.h.in -2 +5
    M ./configure.ac -11 +1
    M ./src/Makefile.am -2 +2
    M ./src/common.c -1 +1
    R ./src/libmoth.c
    R ./src/libmoth.h
    M ./src/moth.c -68 +21
  • Loading branch information...
1 parent 2955bd0 commit 0e267ff4cfc953c8db77285b27c6c2c0d32aff7a stig committed May 9, 2005
Showing with 30 additions and 726 deletions.
  1. +0 −2 PLUGIN/REQ
  2. +0 −1 PLUGIN/auto
  3. +5 −2 config/config.h.in
  4. +1 −11 configure.ac
  5. +2 −2 src/Makefile.am
  6. +1 −1 src/common.c
  7. +0 −581 src/libmoth.c
  8. +0 −58 src/libmoth.h
  9. +21 −68 src/moth.c
View
2 PLUGIN/REQ
@@ -1,2 +0,0 @@
-ggtl moth
-options moth
View
1 PLUGIN/auto
@@ -1 +0,0 @@
-library-test glut -lglut
View
7 config/config.h.in
@@ -1,7 +1,7 @@
/* config/config.h.in. Generated from configure.ac by autoheader. */
-/* Define to 1 if you have the <ggtl/ggtl.h> header file. */
-#undef HAVE_GGTL_GGTL_H
+/* Define to 1 if you have the <ggtl/core.h> header file. */
+#undef HAVE_GGTL_CORE_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
@@ -21,6 +21,9 @@
/* Define to 1 if you have the <options/opt.h> header file. */
#undef HAVE_OPTIONS_OPT_H
+/* Define to 1 if you have the <sl/sl.h> header file. */
+#undef HAVE_SL_SL_H
+
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
View
12 configure.ac
@@ -35,17 +35,7 @@ AC_CHECK_LIB(glut, glutInit)
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([stdlib.h string.h])
-AC_CHECK_HEADERS([options/opt.h], [], [ AC_MSG_ERROR([
- Fatal error -- the options header file is missing.
- options is available at http://brautaset.org/projects/options/
- ])
-])
-AC_CHECK_HEADERS([ggtl/ggtl.h], [], [ AC_MSG_ERROR([
- Fatal error -- the GGTL header file is missing.
- GGTL is available at http://brautaset.org/projects/ggtl/
- ])
-])
+AC_CHECK_HEADERS([stdlib.h string.h ggtl/core.h options/opt.h sl/sl.h])
# Checks for typedefs, structures, and compiler characteristics.
View
4 src/Makefile.am
@@ -6,8 +6,8 @@ endif
COMMON = common.c common.h
-moth_SOURCES = $(COMMON) moth.c libmoth.h libmoth.c
-gmoth_SOURCES = $(COMMON) gmoth.c libmoth.h libmoth.c
+moth_SOURCES = $(COMMON) moth.c
+gmoth_SOURCES = $(COMMON) gmoth.c
c4_SOURCES = $(COMMON) connect4.c libc4.h libc4.c
gc4_SOURCES = $(COMMON) gconnect4.c libc4.h libc4.c
View
2 src/common.c
@@ -11,7 +11,7 @@ void getopts(int argc, char **argv, int *debug, int *fixed, int *level1, int *le
struct opt_defs options[] = {
{"help", "h", 0, "0", "Print a short help message and exit"},
{"longhelp", "H", 0, "0","Print help with default values and exit"},
- {"debug", "d", 0, "0", "Print debug level messages"},
+ {"debug", "d", 1, "-2", "Print debug level messages"},
{"fixed", "f", 0, "0", "Fixed-depth search (turn off iterative deepening)"},
{"level1", "1", 1, "3", "Depth of search (times 10ms for iterative deepening) -- player 1"},
{"level2", "2", 1, "3", "Depth of search (times 10ms for iterative deepening) -- player 2"},
View
581 src/libmoth.c
@@ -1,581 +0,0 @@
-/*
- * moth -- an Othello game
- * Copyright (C) 2003 Stig Brautaset, Dimitris Parapadakis and the
- * University of Westminster, London, UK.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "libmoth.h"
-
-/* One global variable -- whether this should remain global or not is
- * uncertain -- I need to profile the code to know that. Intuitively it
- * should be faster not having to create this on every entry of the
- * evaluation function, but that might not be the case anyway.
- */
-const int heuristic[8][8] = { {9, 2, 7, 8, 8, 7, 2, 9},
- {2, 1, 3, 4, 4, 3, 1, 2},
- {7, 3, 6, 5, 5, 6, 3, 7},
- {8, 4, 5, 1, 1, 5, 4, 8},
- {8, 4, 5, 1, 1, 5, 4, 8},
- {7, 3, 6, 5, 5, 6, 3, 7},
- {2, 1, 3, 4, 4, 3, 1, 2},
- {9, 2, 7, 8, 8, 7, 2, 9}
-};
-
-
-
-/*
- * Print greeting and warranty details.
- */
-void greeting(void)
-{
- puts("This is moth, yet another othello game.");
- puts("Copyright (C) 2003 Stig Brautaset, Dimitris Parapadakis &");
- puts("the University of Westminster, London, UK.");
- puts("This is free software; see the source for details.\n");
- puts("Report bugs to <stig@brautaset.org>.\n");
-}
-
-
-int save(char *fn, struct ggtl *g)
-{
- FILE *fp;
- int retval = 0;
-
- fp = fopen(fn, "w");
- if (!fp)
- return -1;
-
- if (ggtl_save(g, fp, write_pos, write_move)) {
- retval = -1;
- }
-
- if (fclose(fp)) {
- retval = -1;
- }
-
- return retval;
-}
-
-
-struct ggtl *resume(char *fn)
-{
- FILE *fp;
- struct ggtl *g;
-
- fp = fopen(fn, "r");
- if (!fp)
- return NULL;
-
- g = ggtl_new(make_move, end_of_game, find_moves, evaluate);
- if (!g) {
- fclose(fp);
- return NULL;
- }
-
- if (!ggtl_resume(g, fp, read_pos, read_move)) {
- ggtl_free(g);
- fclose(fp);
- return NULL;
- }
-
- if (fclose(fp)) {
- ggtl_free(g);
- return NULL;
- }
-
- return g;
-}
-
-
-int write_move(FILE *fp, struct ggtl_move *mv)
-{
- if (fprintf(fp, "x: %d, y: %d\n", mv->x, mv->y) < 0)
- return -1;
- return 0;
-}
-
-
-struct ggtl_move *read_move(FILE *fp)
-{
- struct ggtl_move *mv;
- int x, y;
-
- if (fscanf(fp, "x: %d, y: %d\n", &x, &y) != 2)
- return NULL;
-
- mv = malloc(sizeof *mv);
- if (!mv)
- return NULL;
-
- mv->next = NULL;
- mv->x = x;
- mv->y = y;
-
- return mv;
-}
-
-
-int write_pos(FILE *fp, struct ggtl_pos *pos)
-{
- int i, j, player;
-
- if (!pos)
- return -1;
- if (fprintf(fp, "player start: %d\n", pos->player) < 0)
- return -1;
-
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- player = pos->b[i][j];
- if (fputc('0' + player, fp) == EOF)
- return -1;
-
- }
- if (fputc('\n', fp) == EOF)
- return -1;
- }
- if (fputc('\n', fp) == EOF)
- return -1;
- return 0;
-}
-
-
-struct ggtl_pos *read_pos(FILE *fp)
-{
- int i, j, player;
- struct ggtl_pos *pos;
-
- if (fscanf(fp, "player start: %d\n", &player) != 1)
- return NULL;
-
- pos = malloc(sizeof *pos);
- if (!pos)
- return NULL;
- pos->next = NULL;
- pos->player = player;
-
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- player = fgetc(fp);
- if (player == EOF) {
- free(pos);
- return NULL;
- }
-
- pos->b[i][j] = player - '0';
- }
- if (fgetc(fp) != '\n') {
- free(pos);
- return NULL;
- }
- }
- if (fgetc(fp) != '\n') {
- free(pos);
- return NULL;
- }
-
- return pos;
-}
-
-
-/**
- * Copy a position. Use cached position if provided, else allocate the
- * necessary memory. Exit if the necessary memory cannot be allocated.
- *
- * @param dst where to copy the position (if non-NULL)
- * @param src the position to copy
- *
- * @return A pointer to the copy of the position is returned.
- */
-struct ggtl_pos *copy_pos(struct ggtl_pos *dst, struct ggtl_pos *src)
-{
- if (!dst) {
- dst = malloc(sizeof *dst);
- if (!dst)
- exit(EXIT_FAILURE);
- dst->next = NULL;
- }
- return memcpy(dst, src, sizeof *src);
-}
-
-
-struct ggtl_move *ensure_move(void)
-{
- struct ggtl_move *pos;
-
- pos = malloc(sizeof *pos);
- if (!pos)
- exit(EXIT_FAILURE);
-
- pos->next = NULL;
- return pos;
-}
-
-
-/*
- * Evaluate a board position for the given player.
- *
- * This function is heavily inspired by code in GNOME Iagno, which is
- * Copyright (C) Ian Peters <ipeters@acm.org>
- */
-int evaluate(struct ggtl_pos *b)
-{
- int c, i, j;
- int me = b->player;
- int not_me = 3 - me;
- int myscore = 0, notmyscore = 0;
-
-#if 1
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- c = b->b[i][j];
- if (c == me) {
- myscore += heuristic[i][j];
- }
- else if (c == not_me) {
- notmyscore += heuristic[i][j];
- }
- }
- }
-#else
- myscore = count_pieces(board, me);
- notmyscore = count_pieces(board, not_me);
-#endif
- if (!myscore) return GGTL_MIN;
- if (!notmyscore) return GGTL_MAX;
- return myscore - notmyscore;
-}
-
-
-/*
- * Find and add possible moves at this position to GGTL's internal
- * lists.
- */
-void find_moves(struct ggtl *game, struct ggtl_pos *b)
-{
- struct ggtl_move *mv;
- int me = b->player;
- int i, j, cnt;
-
- cnt = 0;
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- if (valid_move(b, i, j, me)) {
- mv = ggtl_pop_move(game);
- if (!mv)
- mv = ensure_move();
-
- mv->x = i;
- mv->y = j;
- ggtl_add_move(game, mv);
- cnt++;
- }
- }
- }
-
- if (!cnt) {
- mv = ggtl_pop_move(game);
- if (!mv)
- mv = ensure_move();
-
- /* add a pass move */
- mv->x = mv->y = -1;
- ggtl_add_move(game, mv);
- }
-}
-
-
-/*
- * Return zero if the game has _not_ ended at this position (for the
- * current player), and non-zero if it has.
- */
-int end_of_game(struct ggtl_pos *b)
-{
- int i, j;
- int me = b->player;
-
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- if (valid_move(b, i, j, me))
- return 0;
- }
- }
- return 1;
-}
-
-
-/*
- * This function is heavily inspired by code in GNOME Iagno, which is
- * Copyright (C) Ian Peters <ipeters@acm.org>
- */
-struct ggtl_pos *make_move(struct ggtl *g, struct ggtl_pos *b, struct ggtl_move *m)
-{
- int me = b->player;
- int not_me = 3 - me;
- int tx, ty, flipped = 0;
- int x = m->x;
- int y = m->y;
- struct ggtl_pos *pos;
-
- pos = ggtl_pop_pos(g);
- pos = copy_pos(pos, b);
-
- /* null or pass move */
- if (x == -1 && y == -1) {
- pos->player = 3 - me;
- return pos;
- }
-
- if (x < 0 || x > 7 || y < 0 || y > 7) {
- ggtl_push_pos(g, pos);
- return NULL;
- }
-
- /* slot must not already be occupied */
- if (pos->b[x][y] != 0) {
- ggtl_push_pos(g, pos);
- return NULL;
- }
-
- /* left */
- for (tx = x - 1; tx >= 0 && pos->b[tx][y] == not_me; tx--)
- ;
- if (tx >= 0 && tx != x - 1 && pos->b[tx][y] == me) {
- tx = x - 1;
- while (tx >= 0 && pos->b[tx][y] == not_me) {
- pos->b[tx][y] = me;
- tx--;
- }
- flipped++;
- }
-
- /* right */
- for (tx = x + 1; tx < 8 && pos->b[tx][y] == not_me; tx++)
- ;
- if (tx < 8 && tx != x + 1 && pos->b[tx][y] == me) {
- tx = x + 1;
- while (tx < 8 && pos->b[tx][y] == not_me) {
- pos->b[tx][y] = me;
- tx++;
- }
- flipped++;
- }
-
- /* up */
- for (ty = y - 1; ty >= 0 && pos->b[x][ty] == not_me; ty--)
- ;
- if (ty >= 0 && ty != y - 1 && pos->b[x][ty] == me) {
- ty = y - 1;
- while (ty >= 0 && pos->b[x][ty] == not_me) {
- pos->b[x][ty] = me;
- ty--;
- }
- flipped++;
- }
-
- /* down */
- for (ty = y + 1; ty < 8 && pos->b[x][ty] == not_me; ty++)
- ;
- if (ty < 8 && ty != y + 1 && pos->b[x][ty] == me) {
- ty = y + 1;
- while (ty < 8 && pos->b[x][ty] == not_me) {
- pos->b[x][ty] = me;
- ty++;
- }
- flipped++;
- }
-
- /* up/left */
- tx = x - 1;
- ty = y - 1;
- while (tx >= 0 && ty >= 0 && pos->b[tx][ty] == not_me) {
- tx--; ty--;
- }
- if (tx >= 0 && ty >= 0 && tx != x - 1 && ty != y - 1 &&
- pos->b[tx][ty] == me) {
- tx = x - 1;
- ty = y - 1;
- while (tx >= 0 && ty >= 0 && pos->b[tx][ty] == not_me) {
- pos->b[tx][ty] = me;
- tx--; ty--;
- }
- flipped++;
- }
-
- /* up/right */
- tx = x - 1;
- ty = y + 1;
- while (tx >= 0 && ty < 8 && pos->b[tx][ty] == not_me) {
- tx--; ty++;
- }
- if (tx >= 0 && ty < 8 && tx != x - 1 && ty != y + 1 &&
- pos->b[tx][ty] == me) {
- tx = x - 1;
- ty = y + 1;
- while (tx >= 0 && ty < 8 && pos->b[tx][ty] == not_me) {
- pos->b[tx][ty] = me;
- tx--; ty++;
- }
- flipped++;
- }
-
- /* down/right */
- tx = x + 1;
- ty = y + 1;
- while (tx < 8 && ty < 8 && pos->b[tx][ty] == not_me) {
- tx++; ty++;
- }
- if (tx < 8 && ty < 8 && tx != x + 1 && ty != y + 1 &&
- pos->b[tx][ty] == me) {
- tx = x + 1;
- ty = y + 1;
- while (tx < 8 && ty < 8 && pos->b[tx][ty] == not_me) {
- pos->b[tx][ty] = me;
- tx++; ty++;
- }
- flipped++;
- }
-
- /* down/left */
- tx = x + 1;
- ty = y - 1;
- while (tx < 8 && ty >= 0 && pos->b[tx][ty] == not_me) {
- tx++; ty--;
- }
- if (tx < 8 && ty >= 0 && tx != x + 1 && ty != y - 1 &&
- pos->b[tx][ty] == me) {
- tx = x + 1;
- ty = y - 1;
- while (tx < 8 && ty >= 0 && pos->b[tx][ty] == not_me) {
- pos->b[tx][ty] = me;
- tx++; ty--;
- }
- flipped++;
- }
-
- if (flipped == 0) {
- ggtl_push_pos(g, pos);
- return NULL;
- }
-
- pos->b[x][y] = me;
- pos->player = 3 - me;
-
- return pos;
-}
-
-
-/*
- * This function is heavily inspired by code in GNOME Iagno, which is
- * Copyright (C) Ian Peters <ipeters@acm.org>
- */
-int valid_move(struct ggtl_pos *b, int x, int y, int me)
-{
- int tx, ty;
- int not_me = 3 - me;
-
- /* slot must not already be occupied */
- if (b->b[x][y] != 0)
- return 0;
-
- /* left */
- for (tx = x - 1; tx >= 0 && b->b[tx][y] == not_me; tx--)
- ;
- if (tx >= 0 && tx != x - 1 && b->b[tx][y] == me)
- return 1;
-
- /* right */
- for (tx = x + 1; tx < 8 && b->b[tx][y] == not_me; tx++)
- ;
- if (tx < 8 && tx != x + 1 && b->b[tx][y] == me)
- return 1;
-
- /* up */
- for (ty = y - 1; ty >= 0 && b->b[x][ty] == not_me; ty--)
- ;
- if (ty >= 0 && ty != y - 1 && b->b[x][ty] == me)
- return 1;
-
- /* down */
- for (ty = y + 1; ty < 8 && b->b[x][ty] == not_me; ty++)
- ;
- if (ty < 8 && ty != y + 1 && b->b[x][ty] == me)
- return 1;
-
- /* up/left */
- tx = x - 1;
- ty = y - 1;
- while (tx >= 0 && ty >= 0 && b->b[tx][ty] == not_me) {
- tx--; ty--;
- }
- if (tx >= 0 && ty >= 0 && tx != x - 1 && ty != y - 1 &&
- b->b[tx][ty] == me)
- return 1;
-
- /* up/right */
- tx = x - 1;
- ty = y + 1;
- while (tx >= 0 && ty < 8 && b->b[tx][ty] == not_me) {
- tx--; ty++;
- }
- if (tx >= 0 && ty < 8 && tx != x - 1 && ty != y + 1 &&
- b->b[tx][ty] == me)
- return 1;
-
- /* down/right */
- tx = x + 1;
- ty = y + 1;
- while (tx < 8 && ty < 8 && b->b[tx][ty] == not_me) {
- tx++; ty++;
- }
- if (tx < 8 && ty < 8 && tx != x + 1 && ty != y + 1 &&
- b->b[tx][ty] == me)
- return 1;
-
- /* down/left */
- tx = x + 1;
- ty = y - 1;
- while (tx < 8 && ty >= 0 && b->b[tx][ty] == not_me) {
- tx++; ty--;
- }
- if (tx < 8 && ty >= 0 && tx != x + 1 && ty != y - 1 &&
- b->b[tx][ty] == me)
- return 1;
-
- /* if we get here the move was illegal */
- return 0;
-}
-
-
-/*
- * Count the number of pieces on the board for the given player
- */
-int count_pieces(struct ggtl_pos *b, int me)
-{
- int i, j, count = 0;
-
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- if (b->b[i][j] == me)
- count++;
- }
- }
- return count;
-}
-
View
58 src/libmoth.h
@@ -1,58 +0,0 @@
-/*
- * moth -- an Othello game
- * Copyright (C) 2003 Stig Brautaset, Dimitris Parapadakis and the
- * University of Westminster, London, UK.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef MOTH__MOTH_COMMON_H
-#define MOTH__MOTH_COMMON_H 1
-
-#include <ggtl/ggtl.h>
-#include "common.h"
-
-struct ggtl_pos {
- struct ggtl_pos *next;
- int b[8][8];
- int player;
-};
-
-struct ggtl_move {
- struct ggtl_move *next;
- int x, y;
-};
-
-extern struct opt_defs options[];
-
-
-/* libmoth.c */
-void greeting(void);
-int save(char *fn, struct ggtl *g);
-struct ggtl *resume(char *fn);
-int write_move(FILE *fp, struct ggtl_move *mv);
-struct ggtl_move *read_move(FILE *fp);
-int write_pos(FILE *fp, struct ggtl_pos *pos);
-struct ggtl_pos *read_pos(FILE *fp);
-struct ggtl_pos *copy_pos(struct ggtl_pos *dst, struct ggtl_pos *src);
-struct ggtl_move *ensure_move(void);
-int evaluate(struct ggtl_pos *b);
-void find_moves(struct ggtl *game, struct ggtl_pos *b);
-int end_of_game(struct ggtl_pos *b);
-struct ggtl_pos *make_move(struct ggtl *g, struct ggtl_pos *b, struct ggtl_move *m);
-int valid_move(struct ggtl_pos *b, int x, int y, int me);
-int count_pieces(struct ggtl_pos *b, int me);
-
-#endif
View
89 src/moth.c
@@ -21,36 +21,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include "libmoth.h"
-
-/*
- * Draw a game position on screen.
- */
-static void display(struct ggtl_pos *b)
-{
- int i, j, c;
-
- printf("\n ");
- for (i = 0; i < 8; i++)
- printf(" %d ", i);
- puts("\n +---+---+---+---+---+---+---+---+");
-
- for (i = 0; i < 8; i++) {
- printf("%d |", i);
- for (j = 0; j < 8; j++) {
- c = b->b[i][j];
- if (c == 1)
- printf(" - |");
- else if (c == 2)
- printf(" X |");
- else
- printf(" |");
- }
- puts("\n +---+---+---+---+---+---+---+---+");
-
- }
-}
+#include <ggtl/reversi.h>
/*
@@ -74,17 +46,15 @@ static int getline(char *s, size_t size)
static struct ggtl *mainloop(struct ggtl *game, int fixed, int ply1, int ply2)
{
char move[128] = {0};
- struct ggtl_pos *board;
+ struct reversi_state *board;
int score, ply;
- board = ggtl_peek_pos(game);
for (;;) {
+ board = ggtl_peek_state(game);
if (board) {
- display(board);
+ reversi_state_draw(board);
}
-
- board = ggtl_peek_pos(game);
- if (end_of_game(board)) {
+ if (ggtl_game_over(game)) {
break;
}
printf("\nplayer %d (%c)\n", board->player, board->player==1?'-':'X');
@@ -102,22 +72,17 @@ static struct ggtl *mainloop(struct ggtl *game, int fixed, int ply1, int ply2)
puts("Error: no move to undo\n");
}
}
+#if 0
else if (!strncmp(move, "rate", 4)) {
int ply = ggtl_get(game, GGTL_PLY_LAST);
printf("minimax value: %d\n\n", ggtl_rate_move(game, ply));
board = NULL;
}
+#endif
else if (!strncmp(move, "redisp", 6)) {
- board = ggtl_peek_pos(game);
+ board = ggtl_peek_state(game);
}
- else if (!strncmp(move, "save", 4)) {
- printf("Saving game, need a name: "); fflush(stdout);
- getline(move, sizeof move);
- if (!save(move, game))
- puts("success");
- else puts("failed");
- board = NULL;
- }
+#if 0
else if (!strncmp(move, "load", 4)) {
struct ggtl *tmp;
printf("Loading game, need a name: "); fflush(stdout);
@@ -126,35 +91,26 @@ static struct ggtl *mainloop(struct ggtl *game, int fixed, int ply1, int ply2)
printf("loaded game from `%s'.", move);
ggtl_free(game);
game = tmp;
- board = ggtl_peek_pos(game);
+ board = ggtl_peek_state(game);
}
else {
printf("failed loading game from `%s'.", move);
board = NULL;
}
}
+#endif
else {
- struct ggtl_move *mv;
-
- mv = ggtl_pop_move(game);
- if (!mv)
- mv = ensure_move();
-
- mv->next = NULL;
- mv->x = move[1] - '0';
- mv->y = move[0] - '0';
+ struct reversi_move *mv;
+ mv = reversi_move_new(move[1]-'0', move[0]-'0');
board = ggtl_move(game, mv);
if (!board) {
- ggtl_push_move(game, mv);
- if (fixed)
- board = ggtl_alphabeta(game, ply);
- else
- board = ggtl_alphabeta_iterative(game, ply);
+ ggtl_ai_move(game);
}
}
}
+#if 0
score = count_pieces(board, 1);
score -= count_pieces(board, 2);
@@ -167,30 +123,27 @@ static struct ggtl *mainloop(struct ggtl *game, int fixed, int ply1, int ply2)
else {
puts("The game ended in a draw\n\n");
}
+#endif
return game;
}
int main(int argc, char **argv)
{
struct ggtl *game;
- struct ggtl_pos *pos, start = {NULL, {{0}}, 1};
+ struct reversi_state *pos;
int debug, fixed, level1, level2;
- greeting();
getopts(argc, argv, &debug, &fixed, &level1, &level2);
- start.b[3][4] = start.b[4][3] = 1;
- start.b[3][3] = start.b[4][4] = 2;
+ pos = reversi_state_new(8);
- pos = copy_pos(NULL, &start);
- game = ggtl_new(make_move, end_of_game, find_moves, evaluate);
- if (!ggtl_init(game, pos)) {
- ggtl_free(game);
+ game = reversi_init(ggtl_new(), pos);
+ if (!game) {
puts("sorry -- NO GAME FOR YOU!");
return EXIT_FAILURE;
}
- ggtl_set(game, GGTL_DEBUG, debug);
+ ggtl_ai_trace(game, debug);
game = mainloop(game, fixed, level1, level2);
ggtl_free(game);

0 comments on commit 0e267ff

Please sign in to comment.
Something went wrong with that request. Please try again.