Index: gnome-games/iagno/classic.png
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/classic.png,v
retrieving revision 1.3
diff -u -r1.3 classic.png
Binary files /tmp/cvs8ksEZu and classic.png differ
Index: gnome-games/iagno/gnothello.c
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/gnothello.c,v
retrieving revision 1.136
diff -u -r1.136 gnothello.c
--- gnome-games/iagno/gnothello.c	7 Jul 2006 21:28:15 -0000	1.136
+++ gnome-games/iagno/gnothello.c	23 Aug 2006 22:07:59 -0000
@@ -1,8 +1,5 @@
-/* -*- mode:C; indent-tabs-mode:t; tab-width:8; c-basic-offset:8; -*- */
-
 /*
- * gnothello.c - Main GUI part of iagno
- * written by Ian Peters <itp@gnu.org>
+ * gnothello.c - callback and main code for iagno.
  *
  * 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
@@ -23,795 +20,1229 @@
 
 #include <config.h>
 #include <gnome.h>
-#include <gdk/gdkkeysyms.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
-
-#include <string.h>
+#include <gconf/gconf-client.h>
+#include <stdio.h>
+#include <fcntl.h>
 
 #include "gnothello.h"
-#include "othello.h"
 #include "properties.h"
-#include "games-network.h"
+#include "othello.h"
 #include "network.h"
+#include "games-network.h"
+#include "games-stock.h"
+#include "games-preimage.h"
+
+gint8     pixmaps[8][8];
+gint8     board[8][8];
+guint8    kifu[61][2];
 
-GnomeAppBar *appbar;
 GtkWidget *window;
+GtkWidget *properties_dialog = NULL;
+GtkWidget *file_open_dialog;
+GtkWidget *file_save_dialog;
+
 GtkWidget *drawing_area;
-GtkWidget *tile_dialog;
-GtkWidget *black_score;
-GtkWidget *white_score;
+GtkWidget *score[4];
+GtkWidget *statusbar;
+GtkWidget *entry;
 
 GdkPixmap *buffer_pixmap = NULL;
 GdkPixmap *tiles_pixmap = NULL;
-GdkPixmap *tiles_mask = NULL;
+GdkGC     *gridGC[2] = { 0 };
 
-gint flip_pixmaps_id = 0;
-gint statusbar_id;
-guint black_computer_level;
-guint white_computer_level;
-guint black_computer_id = 0;
-guint white_computer_id = 0;
-guint computer_speed = COMPUTER_MOVE_DELAY;
-gint animate;
-gint animate_stagger;
-gint grid = 0;
-guint tiles_to_flip = 0;
-
-gint64 milliseconds_total = 0;
-gint64 milliseconds_current_start = 0;
-
-guint game_in_progress;
-
-gint8 pixmaps[8][8] = {{0,0,0,0,0,0,0,0},
-		      {0,0,0,0,0,0,0,0},
-		      {0,0,0,0,0,0,0,0},
-		      {0,0,0,0,0,0,0,0},
-		      {0,0,0,0,0,0,0,0},
-		      {0,0,0,0,0,0,0,0},
-		      {0,0,0,0,0,0,0,0},
-		      {0,0,0,0,0,0,0,0}};
-
-gint8 board[8][8] = {{0,0,0,0,0,0,0,0},
-		    {0,0,0,0,0,0,0,0},
-		    {0,0,0,0,0,0,0,0},
-		    {0,0,0,0,0,0,0,0},
-		    {0,0,0,0,0,0,0,0},
-		    {0,0,0,0,0,0,0,0},
-		    {0,0,0,0,0,0,0,0},
-		    {0,0,0,0,0,0,0,0}};
-
-guint whose_turn;
-gint8 move_count;
-gint bcount;
-gint wcount;
-
-extern guint flip_final_id;
-extern gint8 squares[64];
-
-int session_flag = 0;
-int session_xpos = -1;
-int session_ypos = -1;
-int session_position = 0;
-
-gchar *tile_set = NULL;
-gchar *tile_set_tmp = NULL;
-
-GdkGC *gridGC[2] = { 0 };
-
-static void new_network_game_cb(GtkWidget *widget, gpointer data);
-
-static const GOptionEntry options[] = {
-  {"x", 'x', 0, G_OPTION_ARG_INT, &session_xpos, N_("X location of window"), 
-   N_("X")},
-  {"y", 'y', 0, G_OPTION_ARG_INT, &session_ypos, N_("Y location of window"), 
-   N_("Y")},
-  {"server", 's', 0, G_OPTION_ARG_STRING, &game_server, 
-   N_("Iagno server to use"), N_("NAME")},
-  {NULL}
-};
-
-GnomeUIInfo game_menu[] = {
-        GNOMEUIINFO_MENU_NEW_GAME_ITEM(new_game_cb, NULL),
-
-	GNOMEUIINFO_ITEM(N_("New Net_work Game"), NULL, new_network_game_cb, NULL),
-
-	GNOMEUIINFO_SEPARATOR,
-
-	GNOMEUIINFO_MENU_UNDO_MOVE_ITEM(undo_move_cb, NULL),
-	
-	GNOMEUIINFO_SEPARATOR,
-
-        GNOMEUIINFO_MENU_QUIT_ITEM(quit_game_cb, NULL),
-
-	GNOMEUIINFO_END
-};
-
-GnomeUIInfo settings_menu[] = {
-        GNOMEUIINFO_MENU_PREFERENCES_ITEM (properties_cb, NULL),
-        GNOMEUIINFO_END
-};
-
-GnomeUIInfo help_menu[] = {
-        GNOMEUIINFO_HELP("iagno"),
-	GNOMEUIINFO_MENU_ABOUT_ITEM(about_cb, NULL),
-	GNOMEUIINFO_END
-};
-
-GnomeUIInfo mainmenu[] = {
-        GNOMEUIINFO_MENU_GAME_TREE(game_menu),
-        GNOMEUIINFO_MENU_SETTINGS_TREE(settings_menu),
-        GNOMEUIINFO_MENU_HELP_TREE(help_menu),
-	GNOMEUIINFO_END
-};
+guint     board_width;
+guint     board_height;
+guint     tile_width;
+guint     tile_height;
+
+guint     black_computer_level;
+guint     white_computer_level;
+gboolean  quick_moves;
+guint     animate;
+gboolean  animate_stagger;
+gboolean  grid;
+gboolean  flip_final;
+gboolean  fast_cpu;
+gchar     *tile_set;
+gchar     *bg_color_name;
+GdkColor  bg_color = {0,0,0,0};
+
+guint     computer_speed;
+guint     flip_speed;
+gchar     *flip_sound;
+gchar     *gameover_sound;
+gboolean  flip_tiles = FALSE;
+gboolean  play_sound = FALSE;
+gboolean  gameover = FALSE;
+
+guint     context_id = 0;
+guint     computer_id = 0;
+guint     flip_pixmaps_id = 0;
+guint     flip_final_id = 0;
+guint     timer_id;
+GTimer    *b_timer;
+GTimer    *w_timer;
+guint     game_in_progress;
+
+extern gint  vsquares[280][2];
+extern guint bcount;
+extern guint wcount;
+extern guint move_count;
+extern guint whose_turn;
+
+extern gboolean t_options[];
+extern gchar    *t_bg_color_name;
+extern GdkColor t_bg_color;
 
-static void undo_set_sensitive (gboolean state)
+gint
+clamp_int (gint input, gint low, gint high)
 {
-	gtk_widget_set_sensitive (game_menu[3].widget, state);
-}
+	if (input < low)
+		input = low;
+	if (input > high)
+		input = high;
 
-void
-quit_game_cb (GtkWidget *widget, gpointer data)
-{
-  games_kill_server ();
-  gtk_main_quit ();
+	return input;
 }
 
 static void
-new_network_game_cb (GtkWidget *widget, gpointer data)
+copy_pixmaps (void)
 {
-  network_new (window);
+	guint i, j;
+
+	for (i = 0; i < 8; i++)
+		for (j = 0; j < 8; j++)
+			pixmaps[i][j] = board[i][j];
 }
 
 void
-new_game_cb (GtkWidget *widget, gpointer data)
+set_board_size (void)
 {
-  network_stop ();
-  init_new_game ();
+	gint depth = -1;
+	
+	tile_width = (board_width - GRIDWIDTH * 7) / 8;
+	tile_height = (board_height - GRIDWIDTH * 7) / 8;
+	board_width = tile_width * 8 + GRIDWIDTH * 7;
+	board_height = tile_height * 8 + GRIDWIDTH * 7;
+
+	gtk_widget_set_size_request (drawing_area, board_width, board_height);
+	if (buffer_pixmap)
+	{
+		depth = gdk_drawable_get_depth ((GdkDrawable*) drawing_area->window);
+		g_object_unref (buffer_pixmap);
+	}
+	buffer_pixmap =
+		gdk_pixmap_new (drawing_area->window, board_width, board_height, depth);
 }
 
 void
-undo_move_cb (GtkWidget *widget, gpointer data)
+set_bg_color (void)
 {
-	gint8 which_computer, xy;
-
-	if ((black_computer_level && white_computer_level) || move_count == 4)
-		return;
+	GdkColormap *colormap;
+	GdkColor tmp_color = {0xffffffff,0xffff,0xffff,0xffff};
+	
+	gdk_color_parse (bg_color_name, &bg_color);
+	gdk_color_parse (t_bg_color_name, &t_bg_color);
+	colormap = gtk_widget_get_colormap (drawing_area);
+	gdk_colormap_alloc_color (colormap, &bg_color, FALSE, TRUE);
+	t_bg_color.pixel = bg_color.pixel;
+	
+	if (gridGC[0])
+		g_object_unref (gridGC[0]);
+	gridGC[0] = gdk_gc_new (drawing_area->window);
+	if (gridGC[1])
+		g_object_unref (gridGC[1]);
+	gridGC[1] = gdk_gc_new (drawing_area->window);
 
-	if (flip_final_id) {
-		g_source_remove (flip_final_id);
-		flip_final_id = 0;
-	}
+	gdk_gc_copy (gridGC[0], drawing_area->style->bg_gc[0]);
+	gdk_gc_copy (gridGC[1], drawing_area->style->bg_gc[0]);
 
-	game_in_progress = 1;
+	gdk_gc_set_background (gridGC[0], &bg_color);
+	gdk_gc_set_foreground (gridGC[0], &bg_color);
 
- 	which_computer = OTHER_PLAYER (whose_turn);
- 	undo();
- 	board_copy();
- 	xy=squares[move_count];
- 	pixmaps[xy%10-1][xy/10-1] = 100;
-	if ((((whose_turn == WHITE_TURN) && white_computer_level) ||
-	     ((whose_turn == BLACK_TURN) && black_computer_level))
-	    && (move_count > 4)) {
- 		undo();
- 		board_copy();
- 		xy=squares[move_count];
- 		pixmaps[xy%10-1][xy/10-1] = 100;
-	}
-
-	if (whose_turn == WHITE_TURN)
-		gui_message (_("Light's move"));
-	else
-		gui_message (_("Dark's move"));
+	gdk_gc_set_background (gridGC[1], &tmp_color);
+	gdk_gc_set_foreground (gridGC[1], &tmp_color);
 
-	gui_status ();
-	tiles_to_flip = 1;
-	check_computer_players ();
+	g_object_unref (colormap);
 }
 
 void
-black_level_cb (GtkWidget *widget, gpointer data)
+load_pixmaps (void)
 {
-        int tmp;
-
-        tmp = atoi ((gchar *)data);
+	GdkPixbuf *image;
+	GamesPreimage *t_image;
+	gchar *fname, *pathname;
+	gint depth = -1;
+	GdkGC *gc;
+	GError *error = NULL;
+	
+	fname = g_build_filename (_("iagno"), tile_set, NULL);
+	pathname = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP,
+					   fname, TRUE, NULL);
 
-        gnome_config_set_int ("/iagno/Preferences/blacklevel", tmp);
-        gnome_config_sync ();
+	t_image = games_preimage_new_from_file (pathname, &error);
+	if (!t_image)
+		exit (1);
 
-        black_computer_level = tmp;
+	image = games_preimage_render (t_image,
+				tile_width * 8, tile_height * 4, &error);
 
-        check_computer_players ();
+	if (tiles_pixmap)
+	{
+		g_object_unref (tiles_pixmap);
+		depth = gdk_drawable_get_depth ((GdkDrawable*) drawing_area->window);
+	}
+	tiles_pixmap = gdk_pixmap_new (drawing_area->window,
+				tile_width * 8, tile_height * 4, depth);
+	gc = gdk_gc_new (tiles_pixmap);
+	gdk_gc_set_foreground (gc, &bg_color);
+	gdk_gc_set_background (gc, &bg_color);
+	gdk_draw_rectangle (tiles_pixmap, gc, TRUE, 0, 0,
+				tile_width * 8, tile_height * 4);
+	gdk_draw_pixbuf (tiles_pixmap, gc, image, 0, 0, 0, 0,
+				tile_width * 8, tile_height * 4, GDK_RGB_DITHER_NORMAL, 0, 0);
+	
+	g_object_unref (image);
+	g_object_unref (t_image);
+	g_free (fname);
 }
 
-void
-white_level_cb (GtkWidget *widget, gpointer data)
+static void
+gui_draw_pixmap (guint x, guint y, guint which)
 {
-        int tmp;
-
-        tmp = atoi ((gchar *)data);
+	gdk_draw_drawable (drawing_area->window, gridGC[0], tiles_pixmap,
+			    tile_width * (which % 8), tile_height * (which / 8),
+			   (tile_width + GRIDWIDTH) * x, (tile_height + GRIDWIDTH) * y,
+			    tile_width, tile_height);
+	gdk_draw_drawable (buffer_pixmap, gridGC[0], tiles_pixmap,
+			    tile_width * (which % 8), tile_height * (which / 8),
+			   (tile_width + GRIDWIDTH) * x, (tile_height + GRIDWIDTH) * y,
+			    tile_width, tile_height);
+}
 
-        gnome_config_set_int ("/iagno/Preferences/whitelevel", tmp);
-        gnome_config_sync ();
+static void
+gui_draw_pixmap_buffer (guint x, guint y, guint which)
+{
+	gdk_draw_drawable (buffer_pixmap, gridGC[0], tiles_pixmap,
+			    tile_width * (which % 8), tile_height * (which / 8),
+			   (tile_width + GRIDWIDTH) * x,(tile_height + GRIDWIDTH) * y,
+			    tile_width, tile_height);
+}
 
-        white_computer_level = tmp;
+static void
+gui_draw_grid (void)
+{
+	guint i, j = 0;
 
-        check_computer_players ();
+	if (grid)
+		j = 1;
+	gdk_gc_set_line_attributes (gridGC[1], GRIDWIDTH, GDK_LINE_ON_OFF_DASH,
+				    GDK_CAP_BUTT, GDK_JOIN_MITER);
+		
+	for (i = 1; i < 8; i++)
+	{
+		gdk_draw_line (buffer_pixmap, gridGC[j],
+			       (tile_width + GRIDWIDTH) * i - GRIDWIDTH,            0,
+			       (tile_width + GRIDWIDTH) * i - GRIDWIDTH, board_height);
+		gdk_draw_line (buffer_pixmap, gridGC[j],
+			                 0,(tile_height + GRIDWIDTH) * i - GRIDWIDTH,
+			       board_width,(tile_height + GRIDWIDTH) * i - GRIDWIDTH);
+	}
 }
 
 void
-about_cb (GtkWidget *widget, gpointer data)
+redraw_board (void)
 {
-	const gchar *authors[] = {"Ian Peters", NULL};
+	guint i, j, which;
 
-	const gchar *documenters[] = {"Eric Baudais", NULL};
+	copy_pixmaps ();
+	grid = FALSE;
+	gui_draw_grid ();
+	grid = t_options[2];
+	for (i = 0; i < 8; i++)
+		for (j = 0; j < 8; j++)
+		{
+			which = 0;
+			if (pixmaps[i][j] != BLANK)
+				which = (guint) (pixmaps[i][j] - BLACK_TURN + 1);
+			gui_draw_pixmap_buffer (j, i, which);
+		}
+	gui_draw_grid ();
 
-	gtk_show_about_dialog (GTK_WINDOW (window),
-			       "name", _("Iagno"),
-			       "version", VERSION,
-			       "copyright", "Copyright \xc2\xa9 1998-2006 Ian Peters",
-			       "license", "GPL 2+",
-			       "comments",_("A disk flipping game derived from Reversi."),
-			       "authors", authors,
-			       "documenters", documenters, 
-			       "translator_credits", _("translator-credits"),
-			       "logo-icon-name", "gnome-iagno",
-			       "website", "http://www.gnome.org/projects/gnome-games/",
-			       "wrap-license", TRUE,
-			       NULL);
+	gdk_draw_drawable (drawing_area->window, gridGC[0], buffer_pixmap,
+			   0, 0, 0, 0, board_width, board_height);
+	gtk_widget_queue_draw (drawing_area);
 }
 
-void
-properties_cb (GtkWidget *widget, gpointer data)
+static void
+gui_status (void)
 {
-	show_properties_dialog ();
+	gchar message[3];
+
+	sprintf (message, _("%.2d"), bcount);
+	gtk_label_set_text (GTK_LABEL (score[0]), message);
+	sprintf (message, _("%.2d"), wcount);
+	gtk_label_set_text (GTK_LABEL (score[1]), message);
 }
 
-gint
-expose_event (GtkWidget *widget, GdkEventExpose *event)
+static void
+sprint_time (gchar *message, GTimer *timer)
 {
-	gdk_draw_drawable (widget->window,
-			   widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
-			   buffer_pixmap,
-			   event->area.x, event->area.y,
-			   event->area.x, event->area.y,
-			   event->area.width, event->area.height);
+	gint mm, ss;
 
-	return(FALSE);
+	ss = (gint) g_timer_elapsed (timer, NULL);
+	mm = ss / 60;
+	ss -= mm * 60;
+	sprintf (message, _("%.2d:%.2d"), mm, ss);
 }
 
-gint
-configure_event (GtkWidget *widget, GdkEventConfigure *event)
+static void
+gui_timer (void)
 {
-	static int old_width = 0, old_height = 0;
-	guint i, j;
-
-	if (old_width == event->width && old_height == event->height) {
-		return TRUE;
-	} else {
-		old_width = event->width;
-		old_height = event->height;
-	}
+	gchar message[9];
 	
-	if (gridGC[0] != 0) {
-		gdk_draw_rectangle (buffer_pixmap, gridGC[0], 1,
-				    0, 0, BOARDWIDTH, BOARDHEIGHT);
-		for (i = 0; i < 8; i++)
-			for (j = 0; j < 8; j++)
-				gui_draw_pixmap_buffer (pixmaps[i][j], i, j);
-		gui_draw_grid ();
-	}
-	
-	return TRUE;
+	sprint_time (message,b_timer);
+	gtk_label_set_text (GTK_LABEL (score[2]), message);
+	sprint_time (message,w_timer);
+	gtk_label_set_text (GTK_LABEL (score[3]), message);		
 }
 
-gint
-button_press_event (GtkWidget *widget, GdkEventButton *event)
+static void
+timer_start (GTimer *timer)
 {
-	guint x, y;
-
-	if (game_in_progress == 0)
-		return TRUE;
-
-	if (!network_allow ())
-		return TRUE;
-	
-	if ((whose_turn == WHITE_TURN) && white_computer_level)
-		return TRUE;
-
-	if ((whose_turn == BLACK_TURN) && black_computer_level)
-		return TRUE;
-
-	if (event->button == 1) {
-		x = event->x / (TILEWIDTH + GRIDWIDTH);
-		y = event->y / (TILEHEIGHT + GRIDWIDTH);
-		if (is_valid_move (x, y, whose_turn))
-			game_move (x, y, whose_turn);
-	}
-
-	return TRUE;
+	if (timer_id)
+		g_source_remove (timer_id);
+	timer_id = g_timeout_add (500, (GSourceFunc) gui_timer, NULL);
+	g_timer_continue (timer);
 }
 
 void
-gui_draw_pixmap (gint which, gint x, gint y)
+gui_message (gchar *message)
 {
-	gdk_draw_drawable (drawing_area->window, gridGC[0], tiles_pixmap,
-			   (which % 8) * TILEWIDTH, (which / 8) * TILEHEIGHT,
-			   x * (TILEWIDTH + GRIDWIDTH),
-			   y * (TILEHEIGHT + GRIDWIDTH),
-			   TILEWIDTH, TILEHEIGHT);
-	gdk_draw_drawable (buffer_pixmap, gridGC[0], tiles_pixmap,
-			   (which % 8) * TILEWIDTH, (which / 8) * TILEHEIGHT,
-			   x * (TILEWIDTH + GRIDWIDTH),
-			   y * (TILEHEIGHT + GRIDWIDTH),
-			   TILEWIDTH, TILEHEIGHT);
+	if (context_id)
+		gtk_statusbar_pop ((GtkStatusbar *) statusbar, context_id);
+	context_id =
+		gtk_statusbar_get_context_id ((GtkStatusbar *) statusbar, message);
+	gtk_statusbar_push ((GtkStatusbar *) statusbar, context_id, message);
 }
 
-void
-gui_draw_pixmap_buffer (gint which, gint x, gint y)
+static void
+gui_hint (gint yx, gint score)
 {
-	gdk_draw_drawable (buffer_pixmap, gridGC[0], tiles_pixmap,
-			   (which % 8) * TILEWIDTH, (which / 8) * TILEHEIGHT,
-			   x * (TILEWIDTH + GRIDWIDTH),
-			   y * (TILEHEIGHT + GRIDWIDTH),
-			   TILEWIDTH, TILEHEIGHT);
+	gchar message[10];
+
+	message[0] = (gchar) (yx % 10 + 0x40);
+	message[1] = (gchar) (yx / 10 + 0x30);
+	message[2] = 0x20;
+	sprintf (&message[3], _("%d"), score);
+
+	gtk_entry_set_text ((GtkEntry *) entry, message);
 }
 
 void
-gui_draw_grid (void)
+clear_board (void)
 {
-	int i;
-        
-	for (i = 1; i < 8; i++) {
-		gdk_draw_line (buffer_pixmap, gridGC[grid],
-			       i * BOARDWIDTH / 8 - 1, 0,
-			       i * BOARDWIDTH / 8 - 1, BOARDHEIGHT);
-		gdk_draw_line (buffer_pixmap, gridGC[grid],
-			       0, i * BOARDHEIGHT / 8 - 1,
-			       BOARDWIDTH, i * BOARDHEIGHT / 8 - 1);
-	}
-	
-	gdk_draw_drawable (drawing_area->window, gridGC[0], buffer_pixmap,
-			   0, 0, 0, 0, BOARDWIDTH, BOARDHEIGHT);
+	guint i, j;
+
+	game_in_progress = FALSE;
+	move_count = 0;
+	for (i = 0; i < 8; i++)
+		for (j = 0; j < 8; j++)
+			board[i][j] = BLANK;
+
+	bcount = 0;
+	wcount = 0;
 }
 
 void
-load_pixmaps (void)
+init_new_game (void)
 {
-	GdkPixbuf *image;
-	GError    *error = NULL;
-	gchar      *tmp;
-	gchar      *fname;
-
-	g_return_if_fail (tile_set != NULL && tile_set [0] != '0');
-
-	tmp = g_build_filename ("iagno", tile_set, NULL);
-	fname = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP,
-                                           tmp, FALSE, NULL);
-	g_free (tmp);
-
-	if (! g_file_test (fname, G_FILE_TEST_EXISTS)) {
-		g_free (fname);
-		fname = gnome_program_locate_file (NULL,
-						   GNOME_FILE_DOMAIN_APP_PIXMAP,
-		                                   "iagno/classic.png",
-						   FALSE, NULL);
-	}
-
-	if (! g_file_test (fname,
-			   G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
-		g_print (_("Could not find \'%s\' pixmap file\n"), fname);
-		exit (1);
+	if (flip_final_id)
+	{
+		g_source_remove (flip_final_id);
+		flip_final_id = 0;
 	}
-
-	image = gdk_pixbuf_new_from_file (fname, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gdk-pixbuf error %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
+	if (computer_id)
+	{
+		g_source_remove (computer_id);
+		computer_id = 0;
 	}
-
-	gdk_pixbuf_render_pixmap_and_mask_for_colormap (image, 
-							gdk_colormap_get_system(),
-							&tiles_pixmap,
-							&tiles_mask, 127);
-
-	gdk_pixbuf_unref (image);
-	g_free (fname);
+	kifu[0][0] = 0;
+	init ();
+	copy_board ();
+	g_timer_stop (b_timer);
+	g_timer_stop (w_timer);
+	redraw_board ();
+	game_in_progress = TRUE;
+	gui_message (_("Dark's move"));
+	g_timer_start (w_timer);
+	g_timer_stop (w_timer);
+	timer_start (b_timer);
+	check_computer_players ();
 }
 
-gint
+static gboolean
 flip_pixmaps (gpointer data)
 {
-	guint i, j;
-	guint flipped_tiles = 0;
+	guint i, j, which;
+
+	if (play_sound)
+	{
+		gnome_sound_play (flip_sound);
+		play_sound = FALSE;
+	}
+	if (gameover)
+	{
+		gnome_sound_play (gameover_sound);
+		gameover = FALSE;
+	}
 
-	if (! tiles_to_flip)
+	if (!flip_tiles)
 		return TRUE;
-	
+	flip_tiles = FALSE;
 	for (i = 0; i < 8; i++)
-		for (j = 0; j < 8; j++) {
-			/* This first case only happens when undoing the "final flip". */
-			if ((pixmaps[i][j] == 101) && (board[i][j] != 0)) {
+		for (j = 0; j < 8; j++)
+		{
+			if (pixmaps[i][j] == BLANK && board[i][j] != BLANK)
+			{
 				pixmaps[i][j] = board[i][j];
-				gui_draw_pixmap (pixmaps[i][j], i, j);
-				flipped_tiles = 1;				
-			} else if ((pixmaps[i][j] == 100) 
-				   || ((pixmaps[i][j] != 101) && (board[i][j] == 0))) {
-				pixmaps[i][j] = 101;
-				gui_draw_pixmap (0, i, j);
-				flipped_tiles = 1;
-			} else if (pixmaps[i][j] < board[i][j]) {
-				if (animate == 0) {
+				which = clamp_int ((gint)pixmaps[i][j], BLACK_TURN, WHITE_TURN);
+				gui_draw_pixmap (j, i, which - BLACK_TURN + 1);
+				flip_tiles = TRUE;
+			}
+			else if (pixmaps[i][j] != BLANK && board[i][j] == BLANK)
+			{
+				pixmaps[i][j] = BLANK;
+				gui_draw_pixmap (j, i, 0);
+				flip_tiles = TRUE;
+			}
+			else if (pixmaps[i][j] < board[i][j] && board[i][j] != BLANK)
+			{
+				if (animate == 0)
+				{
 					if (pixmaps[i][j] == BLACK_TURN)
 						pixmaps[i][j] = board[i][j];
 					else
 						pixmaps[i][j]++;
-				} else if (animate == 1) {
-					if (pixmaps[i][j] < 1)
-						pixmaps[i][j] += 2;
-					else if (pixmaps[i][j] >= 1 && pixmaps[i][j] < 8)
-						pixmaps[i][j] = 8;
-					else if (pixmaps[i][j] >= 8 && pixmaps[i][j] < 16)
-						pixmaps[i][j] = 16;
-					else if (pixmaps[i][j] >= 16 && pixmaps[i][j] < 23)
-						pixmaps[i][j] = 23;
-					else if (pixmaps[i][j] >= 23 && pixmaps[i][j] < 31)
-						pixmaps[i][j] = 31;
-					else if (pixmaps[i][j] > 31)
-						pixmaps[i][j] = 31;
-				} else if (animate == 2)
+				}
+				else if (animate == 1)
+				{
+					if (pixmaps[i][j] < BLACK_TURN)
+						pixmaps[i][j]++;
+					else if (pixmaps[i][j] == BLACK_TURN)
+						pixmaps[i][j] = BLACK_TURN + 11;
+					else if (pixmaps[i][j] == BLACK_TURN + 11)
+						pixmaps[i][j] = BLACK_TURN + 15;
+					else if (pixmaps[i][j] == BLACK_TURN + 15)
+						pixmaps[i][j] = BLACK_TURN + 19;
+					else if (pixmaps[i][j] == BLACK_TURN + 19)
+						pixmaps[i][j] = WHITE_TURN;
+					else if (pixmaps[i][j] > WHITE_TURN)
+						pixmaps[i][j] = WHITE_TURN;
+				}
+				else if (animate == 2)
 					pixmaps[i][j]++;
-				if (pixmaps[i][j] > 0)
-					gui_draw_pixmap (pixmaps[i][j], i, j);
-				flipped_tiles = 1;
-			} else if (pixmaps[i][j] > board[i][j] && pixmaps[i][j] != 101) {
-				if (animate == 0) {
+
+				which = clamp_int ((gint)pixmaps[i][j], BLACK_TURN, WHITE_TURN);
+				gui_draw_pixmap (j, i, which - BLACK_TURN + 1);
+				flip_tiles = TRUE;
+			}
+			else if (pixmaps[i][j] > board[i][j] && pixmaps[i][j] != BLANK)
+			{
+				if (animate == 0)
+				{
 					if (pixmaps[i][j] == WHITE_TURN)
 						pixmaps[i][j] = board[i][j];
 					else
 						pixmaps[i][j]--;
-				} else if (animate == 1) {
-					if (pixmaps[i][j] > 31)
-						pixmaps[i][j] -= 2;
-					else if (pixmaps[i][j] <= 31 && pixmaps[i][j] > 23)
-						pixmaps[i][j] = 23;
-					else if (pixmaps[i][j] <= 23 && pixmaps[i][j] > 16)
-						pixmaps[i][j] = 16;
-					else if (pixmaps[i][j] <= 16 && pixmaps[i][j] > 8)
-						pixmaps[i][j] = 8;
-					else if (pixmaps[i][j] <= 8 && pixmaps[i][j] > 1)
-						pixmaps[i][j] = 1;
-					else if (pixmaps[i][j] < 1)
-						pixmaps[i][j] = 1;
-				} else if (animate == 2)
+				}
+				else if (animate == 1)
+				{
+					if (pixmaps[i][j] > WHITE_TURN)
+						pixmaps[i][j]--;
+					else if (pixmaps[i][j] == WHITE_TURN)
+						pixmaps[i][j] = BLACK_TURN + 19;
+					else if (pixmaps[i][j] == BLACK_TURN + 19)
+						pixmaps[i][j] = BLACK_TURN + 15;
+					else if (pixmaps[i][j] == BLACK_TURN + 15)
+						pixmaps[i][j] = BLACK_TURN + 11;
+					else if (pixmaps[i][j] == BLACK_TURN + 11)
+						pixmaps[i][j] = BLACK_TURN;
+					else if (pixmaps[i][j] < BLACK_TURN)
+						pixmaps[i][j] = BLACK_TURN;
+				}
+				else if (animate == 2)
 					pixmaps[i][j]--;
-				if (pixmaps[i][j] < 32)
-					gui_draw_pixmap (pixmaps[i][j], i, j);
-				flipped_tiles = 1;
+
+				which = clamp_int ((gint)pixmaps[i][j], BLACK_TURN, WHITE_TURN);
+				gui_draw_pixmap (j, i, which - BLACK_TURN + 1);
+				flip_tiles = TRUE;
 			}
 		}
 
-	if (! flipped_tiles)
-		tiles_to_flip = 0;
-
 	return TRUE;
 }
 
-static void
-redraw_board (void)
+static gboolean
+flip_final_results (gpointer data)
 {
-	guint i, j;
+	guint i;
+	gint8 adder = 0;
 
-	gui_status();
+	i = 0;
+	for (; i < bcount; i++)
+	{
+		board[i / 8][i % 8] = BLACK_TURN;
+		if (pixmaps[i / 8][i % 8] == BLANK)
+			pixmaps[i / 8][i % 8] = WHITE_TURN;
+		if (pixmaps[i / 8][i % 8] == WHITE_TURN)
+		{
+			pixmaps[i / 8][i % 8] += adder;
+			if (animate_stagger)
+				adder++;
+		}
+	}
 
-	for (i = 0; i < 8; i++)
-		for (j = 0; j < 8; j++)
-			gui_draw_pixmap_buffer (pixmaps[i][j], i, j);
+	for (; i < 64 - wcount; i++)
+		board[i / 8][i % 8] = BLANK;
 
-	gui_draw_grid ();
+	for (; i < 64; i++)
+	{
+		board[i / 8][i % 8] = WHITE_TURN;
+		if (pixmaps[i / 8][i % 8] == BLANK)
+			pixmaps[i / 8][i % 8] = BLACK_TURN;
+		if (pixmaps[i / 8][i % 8] == BLACK_TURN)
+		{
+			pixmaps[i / 8][i % 8] -= adder;
+			if (animate_stagger)
+				adder++;
+		}
+	}
+	flip_tiles = TRUE;
+	return FALSE;
 }
 
 void
-clear_board (void)
+set_flip_pixmaps_id (void)
 {
-	guint i, j;
-
-	if (flip_final_id) {
-		g_source_remove (flip_final_id);
-		flip_final_id = 0;
-	}
+	if (flip_pixmaps_id)
+		g_source_remove (flip_pixmaps_id);
 
-	if (black_computer_id) {
-		g_source_remove (black_computer_id);
-		black_computer_id = 0;
+	switch (animate)
+	{
+		case 0:
+			flip_pixmaps_id = g_timeout_add (100, flip_pixmaps, NULL);
+			break;
+		case 1:
+			flip_pixmaps_id = g_timeout_add (flip_speed * 8, flip_pixmaps, NULL);
+			break;
+		default:
+		case 2:
+			flip_pixmaps_id = g_timeout_add (flip_speed, flip_pixmaps, NULL);
+			break;
 	}
+}
 
-	if (white_computer_id) {
-		g_source_remove (white_computer_id);
-		white_computer_id = 0;
+gboolean
+check_valid_moves (void)
+{
+	if (mobility (whose_turn))
+	{
+		if (whose_turn == BLACK_TURN)
+		{
+			gui_message (_("Dark's move"));
+			if (game_in_progress)
+				g_timer_continue (b_timer);
+		}
+		else if (whose_turn == WHITE_TURN)
+		{
+			gui_message (_("Light's move"));
+			if (game_in_progress)
+				g_timer_continue (w_timer);
+		}
+		return TRUE;
 	}
 
-	game_in_progress = 0;
-	move_count = 0;
-	for (i = 0; i < 8; i++)
-		for (j = 0; j < 8; j++)
-			board[i][j] = 0;
-
-	memcpy (pixmaps, board, sizeof (gint8) * 8 * 8);
+	whose_turn = OTHER_PLAYER (whose_turn);
+	if (!mobility (whose_turn))
+	{
+		if (wcount > bcount)
+			gui_message (_("Light player wins!"));
+		if (bcount > wcount)
+			gui_message (_("Dark player wins!"));
+		if (wcount == bcount)
+			gui_message (_("The game was a draw."));
+		game_in_progress = FALSE;
+
+		if (flip_final)
+			flip_final_id = g_timeout_add (computer_speed,
+								flip_final_results, NULL);
 
-	bcount = 0;
-	wcount = 0;
+		gameover = TRUE;
+		return FALSE;
+	}
 
-	redraw_board ();
+	if (whose_turn == BLACK_TURN)
+	{
+		gui_message (_("Light must pass, Dark's move"));
+		if (game_in_progress)
+			g_timer_continue (b_timer);
+	}
+	else if (whose_turn == WHITE_TURN)
+	{
+		gui_message (_("Dark must pass, Light's move"));
+		if (game_in_progress)
+			g_timer_continue (w_timer);
+	}
+	return TRUE;
 }
 
-void
-init_new_game (void)
+gboolean
+check_computer_players (void)
 {
-	clear_board ();
-	game_in_progress = 1;
-	move_count = 4;
-
-	undo_set_sensitive (FALSE);
+	guint level = 0;
 	
-	board[3][3] = WHITE_TURN;
-	board[3][4] = BLACK_TURN;
-	board[4][3] = BLACK_TURN;
-	board[4][4] = WHITE_TURN;
+	if (computer_id)
+	{
+		g_source_remove (computer_id);
+		computer_id = 0;
+	}
+	if (black_computer_level && whose_turn == BLACK_TURN)
+		level = black_computer_level;
+	else if (white_computer_level && whose_turn == WHITE_TURN)
+		level = white_computer_level;
+	if (level)
+	{
+		gtk_entry_set_text ((GtkEntry *) entry,_("Now thinking."));
+		computer_id = g_timeout_add (computer_speed,
+						   (GSourceFunc) computer_move, (gpointer) level);
+	}
+	return FALSE;
+}
 
-	bcount = 2;
-	wcount = 2;
-	init();
+gboolean
+move (guint x, guint y)
+{
+	guint yx;
 
-	memcpy (pixmaps, board, sizeof (gint8) * 8 * 8);
+	if (!is_valid_move (x, y, whose_turn))
+		return FALSE;
 
-	redraw_board ();
+	yx = y * 10 + x;
 
-	whose_turn = BLACK_TURN;
-	gui_message (_("Dark's move"));
+	if (game_in_progress)
+	{
+		kifu[move_count - 4][0] = (guint8) whose_turn;
+		kifu[move_count - 4][1] = (guint8) yx;
+		kifu[move_count - 3][0] = 0;
+		if (whose_turn == BLACK_TURN)
+			g_timer_stop (b_timer);
+		else
+			g_timer_stop (w_timer);
+	}
+	move_board (yx);
+	gtk_entry_set_text ((GtkEntry *) entry, _(" "));
+	gtk_entry_set_position ((GtkEntry *) entry, 0);
+	copy_board ();
+	gui_status ();
+	flip_tiles = TRUE;
+	play_sound = TRUE;
+	check_valid_moves ();
+	if (game_in_progress)
+		return check_computer_players ();
 
-	check_computer_players ();
+	return FALSE;
 }
 
-void
-create_window (void)
+static void
+on_open_activate (GtkMenuItem *menuitem, gpointer user_data)
 {
-	GtkWidget *table;
-
-	window = gnome_app_new ("iagno", _("Iagno"));
+	network_stop ();
+	game_in_progress = FALSE;
+	g_timer_stop (b_timer);
+	g_timer_stop (w_timer);
+	g_timer_reset (b_timer);
+	g_timer_reset (w_timer);
+	gui_timer ();
+	kifu[0][0] = 0;
+	file_open_dialog = create_file_open_dialog ();
+	gtk_widget_show (file_open_dialog);
+}
 
-	gtk_widget_realize (window);
-	gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
-	g_signal_connect (G_OBJECT (window), "delete_event",
-			  G_CALLBACK (quit_game_cb), NULL);
+static void
+on_save_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	GDate *date;
+	gchar filename[17];
 
-	gnome_app_create_menus (GNOME_APP (window), mainmenu);
+	date = g_date_new ();
+	g_date_set_time_t (date, time (NULL));
+	g_date_strftime (filename, 17, _("%y%m%d%H"), date);
+
+	file_save_dialog = create_file_save_dialog ();
+	gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER
+					   (file_save_dialog), filename);
+	gtk_widget_show (file_save_dialog);
+	g_date_free (date);
+}
 
-	drawing_area = gtk_drawing_area_new ();
+static void
+on_quit_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	games_kill_server ();
+	gtk_main_quit ();
+}
 
-	gtk_widget_pop_colormap ();
+static void
+on_new_game_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	network_stop ();
+	init_new_game ();
+}
 
-	gnome_app_set_contents (GNOME_APP (window), drawing_area);
+static void
+on_network_game_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	network_new (window);
+}
 
-	gtk_widget_set_size_request (GTK_WIDGET (drawing_area),
-				     BOARDWIDTH, BOARDHEIGHT);
-	g_signal_connect (G_OBJECT (drawing_area), "expose_event",
-			  G_CALLBACK (expose_event), NULL);
-	g_signal_connect (G_OBJECT (window), "configure_event",
-			  G_CALLBACK (configure_event), NULL);
-	g_signal_connect (G_OBJECT (drawing_area), "button_press_event",
-			  G_CALLBACK (button_press_event), NULL);
-	gtk_widget_set_events (drawing_area,
-			       GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
-        /* We do our own double-buffering. */
-        gtk_widget_set_double_buffered (drawing_area, FALSE);
+static void
+on_redo_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	if (is_network_running ())
+		return;
+	if (!network_allow ())
+		network_stop ();
+	if (game_in_progress)
+		return;
+	if (move_count < 4 || move_count > 63)
+		return;
+	
+	game_in_progress = TRUE;
+	kifu[move_count - 4][0] = 0;
+	check_valid_moves ();
+	check_computer_players ();
+}
 
-	gtk_widget_show (drawing_area);
+static void
+on_hint_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	guint tmp;
 
-	appbar = GNOME_APPBAR (gnome_appbar_new (FALSE, TRUE, FALSE));
-	gnome_app_set_statusbar (GNOME_APP (window), GTK_WIDGET (appbar));
-	gnome_app_install_menu_hints (GNOME_APP (window), mainmenu);
+	if (move_count < 4 || move_count > 63)
+		return;
+	if (!mobility (whose_turn))
+		return;
 
-	table = gtk_table_new (1, 8, FALSE);
+	tmp = game_in_progress;
+	game_in_progress = FALSE;
+	computer_move (4);
+	game_in_progress = tmp;
+	gui_hint (vsquares[0][0], vsquares[0][1]);
+}
 
-	black_score = gtk_label_new (_("Dark:"));
-	gtk_widget_show (black_score);
+static void
+on_properties_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	if (properties_dialog)
+		return;
+	properties_dialog = create_properties_dialog ();
+	gtk_widget_show (properties_dialog);
+}
 
-	gtk_table_attach (GTK_TABLE (table), black_score, 1, 2, 0, 1, 0, 0, 3, 1);
+static void on_help_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	gnome_help_display ("iagno.xml", NULL, NULL);
+}
 
-	black_score = gtk_label_new ("00");
-	gtk_widget_show (black_score);
+static void
+on_about_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	const gchar *authors[] = {"Ian Peters", NULL};
 
-	gtk_table_attach (GTK_TABLE (table), black_score, 2, 3, 0, 1, 0, 0, 3, 1);
+	gtk_show_about_dialog (GTK_WINDOW (window),
+			       "name", _("Iagno"),
+			       "version", VERSION,
+			       "copyright", "Copyright \xc2\xa9 1998-2004 Ian Peters",
+			       "comments",_("A disk flipping game derived from Reversi."),
+			       "authors", authors, 
+			       "translator_credits", _("translator-credits"),
+			       NULL);
+}
 
-	white_score = gtk_label_new (_("Light:"));
-	gtk_widget_show (white_score);
+void
+on_head_button_clicked (GtkToolButton *toolbutton, gpointer user_data)
+{
+	if (is_network_running ())
+		return;
+	if (flip_final_id)
+	{
+		g_source_remove (flip_final_id);
+		flip_final_id = 0;
+	}
+	if (game_in_progress)
+	{
+		game_in_progress = FALSE;
+		if (whose_turn == BLACK_TURN)
+			g_timer_stop (b_timer);
+		else
+			g_timer_stop (w_timer);
+	}
+	init ();
+	copy_board ();
+	copy_pixmaps ();
+	redraw_board ();
+	gui_message (_("Dark's move"));
+}
 
-	gtk_table_attach (GTK_TABLE (table), white_score, 4, 5, 0, 1, 0, 0, 3, 1);
+static void
+on_back_button_clicked (GtkToolButton *toolbutton, gpointer user_data)
+{
+	if (is_network_running ())
+		return;
+	if (move_count <= 4)
+		return;
+	if (flip_final_id)
+	{
+		g_source_remove (flip_final_id);
+		flip_final_id = 0;
+	}
+	if (game_in_progress)
+	{
+		game_in_progress = FALSE;
+		if (whose_turn == BLACK_TURN)
+			g_timer_stop (b_timer);
+		else
+			g_timer_stop (w_timer);
+	}
+	back ();
+	copy_board ();
+	gui_status ();
+	flip_tiles = TRUE;
+	play_sound = TRUE;
+	check_valid_moves ();
+}
 
-	white_score = gtk_label_new ("00");
-	gtk_widget_show (white_score);
+static void
+on_forward_button_clicked (GtkToolButton *toolbutton, gpointer user_data)
+{
+	guint yx, who;
 
-	gtk_table_attach (GTK_TABLE (table), white_score, 5, 6, 0, 1, 0, 0, 3, 1);
-	undo_set_sensitive (FALSE);
+	if (is_network_running ())
+		return;
+	game_in_progress = FALSE;
+	who = (guint) kifu[move_count - 4][0];
+	if (!who)
+	{
+		if (check_valid_moves ())
+		{
+			game_in_progress = TRUE;
+			check_computer_players ();
+		}
+		return;
+	}
+	whose_turn = who;
+	yx = (guint) kifu[move_count - 4][1];
+	move (yx % 10, yx / 10);
+	check_valid_moves ();
+}
 
-	gtk_widget_show (table);
+static void
+on_last_button_clicked (GtkToolButton *toolbutton, gpointer user_data)
+{
+	if (is_network_running ())
+		return;
+	game_in_progress = FALSE;
+	while (kifu[move_count - 4][0])
+	{
+		whose_turn = (guint) kifu[move_count - 4][0];
+		move_board ((guint) kifu[move_count - 4][1]);
+	}
+	copy_board ();
+	copy_pixmaps ();
+	redraw_board ();
+	if (check_valid_moves ())
+		{
+			game_in_progress = TRUE;
+			check_computer_players ();
+		}
+}
 
-	gtk_box_pack_start (GTK_BOX (appbar), table, FALSE, TRUE, 0);
+static gboolean
+on_drawing_area_expose_event (GtkWidget *widget,
+					GdkEventExpose *event, gpointer user_data)
+{
+	gdk_draw_drawable (widget->window,
+			   widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
+			   buffer_pixmap,
+			   event->area.x, event->area.y,
+			   event->area.x, event->area.y,
+			   event->area.width, event->area.height);
 
-	gnome_appbar_set_status (GNOME_APPBAR (appbar),
-				 _("Welcome to Iagno!"));
+	return FALSE;
 }
 
-void
-gui_status (void)
+static gboolean
+on_drawing_area_button_press_event (GtkWidget *widget,
+				    GdkEventButton *event, gpointer user_data)
 {
-	gchar message[3];
+	guint x, y;
+ 	
+	if (!network_allow ())
+		return FALSE;
+	if (!game_in_progress)
+		return FALSE;
+	if ((whose_turn == WHITE_TURN) && white_computer_level)
+		return FALSE;
+	if ((whose_turn == BLACK_TURN) && black_computer_level)
+		return FALSE;
 
-	sprintf (message, _("%.2d"), bcount);
-	gtk_label_set_text (GTK_LABEL (black_score), message);
-	sprintf (message, _("%.2d"), wcount);
-	gtk_label_set_text (GTK_LABEL (white_score), message);
-	undo_set_sensitive (move_count > 0 && !is_network_running ());
+	if (event->button)
+	{
+		x = event->x / (tile_width + GRIDWIDTH) + 1;
+		y = event->y / (tile_height + GRIDWIDTH) + 1;
+		if (is_valid_move (x, y, whose_turn))
+			game_move (x, y, whose_turn);
+	}
+
+	return FALSE;
 }
 
-void
-gui_message (gchar *message)
+static gboolean
+on_entry_key_press_event (GtkWidget *widget,
+					GdkEventKey *event, gpointer user_data)
 {
-	gnome_appbar_pop (GNOME_APPBAR (appbar));
-        gnome_appbar_push (GNOME_APPBAR (appbar), message);
+	gchar *ch;
+	guint x, y;
+
+	ch = gtk_entry_get_text ((GtkEntry *) entry);
+	x = (guint) ((*ch++ & 0xdf) - 0x40);
+	y = (guint) (*ch - 0x30);
+	if (x < 1 || x > 8 || y < 1 || y > 8)
+		return FALSE;
+	if (is_valid_move (x, y, whose_turn))
+	{
+		game_move (x, y, whose_turn);
+	}
+	return FALSE;
 }
 
-guint
-check_computer_players (void)
+static gboolean
+on_drawing_area_configure_event (GtkWidget *widget,
+					GdkEventConfigure *event, gpointer user_data)
 {
-	if (black_computer_level && whose_turn == BLACK_TURN)
-		switch (black_computer_level) {
-		case 1:
-			black_computer_id = g_timeout_add (computer_speed, (GSourceFunc)computer_move_1, (gpointer) BLACK_TURN);
-			break;
-		case 2:
-			black_computer_id = g_timeout_add (computer_speed, (GSourceFunc)computer_move_2, (gpointer) BLACK_TURN);
-			break;
-		case 3:
-			black_computer_id = g_timeout_add (computer_speed, (GSourceFunc)computer_move_3, (gpointer) BLACK_TURN);
-			break;
-		}
+/* I don't use this parts because too slow to resize board.
+ But it's possible to use insted of next on_drawing_area_scroll_event().
 	
-	if (white_computer_level && whose_turn == WHITE_TURN)
-		switch (white_computer_level) {
-		case 1:
-			white_computer_id = g_timeout_add (computer_speed, (GSourceFunc)computer_move_1, (gpointer) WHITE_TURN);
-			break;
-		case 2:
-			white_computer_id = g_timeout_add (computer_speed, (GSourceFunc)computer_move_2, (gpointer) WHITE_TURN);
-			break;
-		case 3:
-			white_computer_id = g_timeout_add (computer_speed, (GSourceFunc)computer_move_3, (gpointer) WHITE_TURN);
-			break;
-		}
-
-	return TRUE;
+	GConfClient *client;
+	guint t_width,t_height;
+	
+	t_width = (event->width * 99) / 100;
+	t_height = (event->height * 99) / 100;
+	if (t_width < BOARD_MIN || t_height < BOARD_MIN)
+		return FALSE;		
+
+	board_width = t_width;
+	board_height = t_height;
+
+	client = gconf_client_get_default ();
+	gconf_client_set_int (client, KEY_BOARD_WIDTH, board_width, NULL);
+	gconf_client_set_int (client, KEY_BOARD_HEIGHT, board_height, NULL);
+	g_object_unref (client);
+*/
+	load_properties ();
+	reset_properties ();
+	apply_changes ();
+	return FALSE;
 }
 
-void
-set_bg_color (void)
+static gboolean
+on_drawing_area_scroll_event (GtkWidget *widget,
+					GdkEventScroll *event, gpointer user_data)
 {
-	GdkImage *tmpimage;
-	GdkColor bgcolor;
-
-	tmpimage = gdk_drawable_get_image (tiles_pixmap, 0, 0, 1, 1);
-	bgcolor.pixel = gdk_image_get_pixel (tmpimage, 0, 0);
-	gdk_window_set_background (drawing_area->window, &bgcolor);
+	GConfClient *client;
+	guint t_width, t_height;
+	
+	if (event->type != GDK_SCROLL)
+		return FALSE;
 
-	if (gridGC[0])
-	  g_object_unref (gridGC[0]);
-	gridGC[0] = gdk_gc_new (drawing_area->window);
-	if (gridGC[1])
-	  g_object_unref (gridGC[1]);
-	gridGC[1] = gdk_gc_new (drawing_area->window);
+	if (event->direction == GDK_SCROLL_UP)
+		t_width = t_height = (board_width * 99) / 100;
+	if (event->direction == GDK_SCROLL_DOWN)
+		t_width = t_height = (board_width * 103) / 100;
+	/* It's necessary +dx >= 8.  280*0.03= 8.4 */
 
-	gdk_gc_copy (gridGC [0],drawing_area->style->bg_gc[0]);
-	gdk_gc_copy (gridGC [1],drawing_area->style->bg_gc[0]);
-	
-	gdk_gc_set_background (gridGC [0],&bgcolor);
-	gdk_gc_set_foreground (gridGC [0],&bgcolor);
+	if (t_width < BOARD_MIN || t_width > BOARD_W_MAX)
+		return FALSE;		
 	
-	/* Create a complementary color to use for the ON state */
-	bgcolor.pixel = 0xFFFFFF - bgcolor.pixel;
-	gdk_gc_set_background (gridGC [1],&bgcolor);
-	gdk_gc_set_foreground (gridGC [1],&bgcolor);
+	client = gconf_client_get_default ();
+	gconf_client_set_int (client, KEY_BOARD_WIDTH, t_width, NULL);
+	gconf_client_set_int (client, KEY_BOARD_HEIGHT, t_height, NULL);
+	g_object_unref (client);
 
-	gdk_gc_set_line_attributes (gridGC [1], 0,
-				    GDK_LINE_ON_OFF_DASH,
-				    GDK_CAP_BUTT, GDK_JOIN_MITER);
-	
-	g_object_unref (tmpimage);
+	return on_drawing_area_configure_event (NULL,NULL,NULL);
 }
 
-static int
-save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style,
-	    gint shutdown, GnomeInteractStyle interact_style,
-	    gint fast, gpointer client_data)
-{
-	char *argv[20];
-	int i;
-	gint xpos, ypos;
+static GtkWidget *
+create_window (void)
+{	
+	const char manager_definition[] =
+		"<ui>"
+		"  <menubar name='MenuBar'>"
+		"    <menu name='FileMenu'			action='file-menu'>"
+		"      <menuitem name='Open'			action='open'/>"
+		"      <menuitem name='Save'			action='save'/>"
+		"      <separator/>"
+		"      <menuitem name='Quit'			action='quit-game'/>"
+		"    </menu>"
+		"    <menu name='GameMenu'			action='game-menu'>"
+		"      <menuitem name='New Game'		action='new-game'/>"
+		"      <menuitem name='Net_Work Game'	action='network'/>"
+		"      <menuitem name='Redo'			action='redo-game'/>"
+		"      <menuitem name='Hint'			action='show_hint'/>"
+		"    </menu>"
+		"    <menu name='SettingsMenu'		action='settings-menu'>"
+		"      <menuitem name='Preferences'		action='properties'/>"
+		"    </menu>"
+		"    <menu name='HelpMenu'			action='help-menu'>"
+		"      <menuitem name='Contents'		action='show-help'/>"
+		"      <menuitem name='About'			action='about'/>"
+		"    </menu>"
+		"  </menubar>"
+		"  <toolbar  name='ToolBar'>"
+		"      <toolitem name='Head'		action='head'/>"
+		"      <toolitem name='Back'		action='back'/>"
+		"      <toolitem name='Forward'		action='forward'/>"
+		"      <toolitem name='Last'		action='last'/>"
+		"      <toolitem name='Hint'		action='hint'/>"
+		"      <toolitem name='Redo'		action='redo'/>"
+		"      <toolitem name='New'			action='new'/>"
+		"      <toolitem name='Quit'		action='quit'/>"
+		"  </toolbar>"
+		"</ui>";
+
+	const GtkActionEntry entries[] = {
+		{"file-menu", NULL, N_("_File")},
+		{"open", GTK_STOCK_OPEN, NULL, NULL, NULL,
+		 G_CALLBACK (on_open_activate)},
+		{"save", GTK_STOCK_SAVE, NULL, NULL, NULL,
+		 G_CALLBACK (on_save_activate)},
+		{"quit-game", GTK_STOCK_QUIT, NULL, NULL, NULL,
+		 G_CALLBACK (on_quit_activate)},
+		{"game-menu", NULL, N_("_Game")},
+		{"new-game", GAMES_STOCK_NEW_GAME, NULL, NULL, NULL,
+		 G_CALLBACK (on_new_game_activate)},
+		{"network", GTK_STOCK_NETWORK, NULL, NULL, NULL,
+		 G_CALLBACK (on_network_game_activate)},
+		{"redo-game", GTK_STOCK_REDO, NULL, NULL, NULL,
+		 G_CALLBACK (on_redo_activate)},
+		{"show_hint", GAMES_STOCK_HINT, NULL, NULL, NULL,
+		 G_CALLBACK (on_hint_activate)},
+		{"settings-menu", NULL, N_("_Settings")},
+		{"properties", GTK_STOCK_PREFERENCES, NULL, NULL, NULL,
+		 G_CALLBACK (on_properties_activate)},
+		{"help-menu", NULL, N_("_Help")},
+		{"show-help", GAMES_STOCK_CONTENTS, NULL, NULL, NULL,
+		 G_CALLBACK (on_help_activate)},
+		{"about", GTK_STOCK_ABOUT, NULL, NULL, NULL,
+		 G_CALLBACK (on_about_activate)},
+		{"head", GTK_STOCK_GOTO_FIRST, NULL, "<Ctl><Shift>f" , NULL,
+		 G_CALLBACK (on_head_button_clicked)},
+		{"back", GTK_STOCK_GO_BACK, NULL, "<Ctl>b", NULL,
+		 G_CALLBACK (on_back_button_clicked)},
+		{"forward", GTK_STOCK_GO_FORWARD, NULL, "<Ctl>f", NULL,
+		 G_CALLBACK (on_forward_button_clicked)},
+		{"last", GTK_STOCK_GOTO_LAST, NULL,"<Ctl>l" , NULL,
+		 G_CALLBACK (on_last_button_clicked)},
+		{"hint", GAMES_STOCK_HINT, NULL, "<Ctl>h", NULL,
+		 G_CALLBACK (on_hint_activate)},
+		{"redo", GTK_STOCK_REDO, NULL,"<Ctl>r" , NULL,
+		 G_CALLBACK (on_redo_activate)},
+		{"new", GAMES_STOCK_NEW_GAME, NULL, NULL, NULL,
+		 G_CALLBACK (on_new_game_activate)},
+		{"quit", GTK_STOCK_QUIT, NULL, NULL, NULL,
+		 G_CALLBACK (on_quit_activate)},
+	};
+
+	const gchar *strs[] =
+	{
+		N_("Dark"),
+		N_("Light"),
+		_("00"),
+		_("00:00")
+	};
+
+	GtkWidget *window;
+	GtkWidget *vbox1;
+	GtkWidget *hbox;
+	GtkWidget *label;
+	GtkWidget *vbox2;
+	GtkAccelGroup *accel_group;
+
+	gint i,j;
+	gchar name[2] = { 0, 0 };
+	gchar *markup;
+	
+	GtkActionGroup *action_group;
+	GtkUIManager *manager;
+	GError *error = NULL;
+
+	accel_group = gtk_accel_group_new ();
+
+	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+	gtk_window_set_title (GTK_WINDOW (window), _("iagno"));
+	gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
+	g_signal_connect ((gpointer) window, "destroy",
+				G_CALLBACK (on_quit_activate), NULL);
+
+	manager = gtk_ui_manager_new ();
+	gtk_ui_manager_add_ui_from_string (manager, manager_definition, -1, &error);
+	action_group = gtk_action_group_new ("ActionGroup");
+	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
+	gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window);
+	gtk_ui_manager_insert_action_group (manager, action_group, 0);
+	gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (manager));
+
+	vbox1 = gtk_vbox_new (FALSE, 0);
+	gtk_widget_show (vbox1);
+	gtk_container_add (GTK_CONTAINER (window), vbox1);
+	gtk_box_pack_start (GTK_BOX (vbox1), gtk_ui_manager_get_widget (manager, "/MenuBar"), FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox1), gtk_ui_manager_get_widget (manager, "/ToolBar"), FALSE, FALSE, 0);
+	for (i = 0; i < 8; i++)
+		gtk_tool_item_set_homogeneous (
+			gtk_toolbar_get_nth_item ((GtkToolbar *)gtk_ui_manager_get_widget (
+						manager, "/ToolBar"), i), FALSE);
+
+	hbox = gtk_hbox_new (FALSE, 0);
+	gtk_widget_show (hbox);
+	gtk_box_pack_start (GTK_BOX (vbox1), hbox, TRUE, TRUE, 0);
+
+	label = gtk_label_new (_("  "));
+	gtk_widget_show (label);
+	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+	gtk_widget_set_size_request (label, 17, 17);
+
+	for (*name = 0x41; *name < 0x49; (*name)++)
+	{
+		label = gtk_label_new (name);
+		gtk_widget_show (label);
+		gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+		gtk_widget_set_size_request (label, -1, 17);
+		markup = g_markup_printf_escaped (
+			"<span foreground=\"red\">%s</span>", name);
+		gtk_label_set_markup_with_mnemonic ((GtkLabel *)label, markup);
+		g_free (markup);
+	}
+	
+	hbox = gtk_hbox_new (FALSE, 0);
+	gtk_widget_show (hbox);
+	gtk_box_pack_start (GTK_BOX (vbox1), hbox, TRUE, TRUE, 0);
+
+	vbox2 = gtk_vbox_new (FALSE, 0);
+	gtk_widget_show (vbox2);
+	gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
+
+	for (*name = 0x31; *name < 0x39; (*name)++)
+	{
+		label = gtk_label_new (name);
+		gtk_widget_show (label);
+		gtk_box_pack_start (GTK_BOX (vbox2), label, TRUE, TRUE, 0);
+		gtk_widget_set_size_request (label, 17, -1);
+		markup = g_markup_printf_escaped (
+			"<span foreground=\"red\">%s</span>", name);
+		gtk_label_set_markup_with_mnemonic ((GtkLabel *)label, markup);
+		g_free (markup);
+	}
 
-	gdk_window_get_origin (window->window, &xpos, &ypos);
+	drawing_area = gtk_drawing_area_new ();
+	gtk_widget_show (drawing_area);
+	gtk_widget_set_size_request (drawing_area, board_width, board_height);
+	gtk_box_pack_start (GTK_BOX (hbox), drawing_area, TRUE, TRUE, 0);
+	gtk_widget_set_events (drawing_area, GDK_BUTTON_PRESS_MASK);
+	g_signal_connect ((gpointer) drawing_area, "button_press_event",
+				G_CALLBACK (on_drawing_area_button_press_event), NULL);
+	g_signal_connect ((gpointer) drawing_area, "expose_event",
+				G_CALLBACK (on_drawing_area_expose_event), NULL);
+	g_signal_connect ((gpointer) drawing_area, "configure_event",
+				G_CALLBACK (on_drawing_area_configure_event), NULL);
+	g_signal_connect ((gpointer) drawing_area, "scroll_event",
+				G_CALLBACK (on_drawing_area_scroll_event), NULL);
+
+	hbox = gtk_hbox_new (FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox1), hbox, TRUE, TRUE, 0);
+
+	for (i = 0; i < 2; i++)
+		for (j = 0; j < 2; j++)
+		{
+			label = gtk_label_new (strs[j]);
+			gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+			score[i*2+j] = gtk_label_new (strs[i+2]);
+			gtk_box_pack_start (GTK_BOX (hbox), score[i*2+j], TRUE, TRUE, 0);
+		}
 
-	i = 0;
-	argv[i++] = (char *)client_data;
-	argv[i++] = "-x";
-	argv[i++] = g_strdup_printf ("%d", xpos);
-	argv[i++] = "-y";
-	argv[i++] = g_strdup_printf ("%d", ypos);
+	hbox = gtk_hbox_new (FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox1), hbox, TRUE, TRUE, 0);
 
-	gnome_client_set_restart_command (client, i, argv);
-	gnome_client_set_clone_command (client, 0, NULL);
+	statusbar = gtk_statusbar_new ();
+	gtk_box_pack_start (GTK_BOX (hbox), statusbar, TRUE, TRUE, 0);
+	gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
+
+	entry = gtk_entry_new ();
+	gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
+	gtk_widget_set_events (entry, GDK_KEY_PRESS_MASK);
+	g_signal_connect ((gpointer) entry, "key_press_event",
+			  G_CALLBACK (on_entry_key_press_event), NULL);
+
+	gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
+
+	gtk_widget_show_all (window);
+	gtk_widget_grab_focus (entry);
+	return window;
+}
 
-	g_free (argv[2]);
-	g_free (argv[4]);
+static void
+set_sound (void)
+{
+	gchar *tmp;
 
-	return TRUE;
+	tmp = g_build_filename (_("iagno"), _("flip-piece.wav"), NULL);
+	flip_sound =
+		gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_SOUND,
+					   tmp, TRUE, NULL);
+	g_free (tmp);
+	tmp = g_build_filename (_("iagno"), _("gameover.wav"), NULL);
+	gameover_sound =
+		gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_SOUND,
+					   tmp, TRUE, NULL);
+	g_free (tmp);
 }
 
 int
-main (int argc, char **argv)
-{
-	GnomeClient *client;
-	GnomeProgram *program;
-	GOptionContext *context;
-
+main (int argc, char *argv[])
+{	
 	gnome_score_init ("iagno");
 
 	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 	textdomain (GETTEXT_PACKAGE);
 
-        context = g_option_context_new ("");
-        g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
-
-	program = gnome_program_init ("iagno", VERSION,
-				      LIBGNOMEUI_MODULE,
-				      argc, argv,
-				      GNOME_PARAM_GOPTION_CONTEXT, context,
-				      GNOME_PARAM_APP_DATADIR, DATADIR, NULL);
-
-	gtk_window_set_default_icon_name ("gnome-iagno");
-
-	client= gnome_master_client ();
-
-	g_object_ref (G_OBJECT (client));
+	gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv,
+			    GNOME_PARAM_APP_DATADIR, DATADIR, NULL);
 
-	g_signal_connect (G_OBJECT (client), "save_yourself",
-			  G_CALLBACK (save_state), argv[0]);
-	g_signal_connect (G_OBJECT (client), "die",
-			  G_CALLBACK (quit_game_cb), argv[0]);
+	gconf_init (argc, argv, NULL);
+	games_stock_init ();
+	gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/gnome-iagno.png");
 
-	create_window ();
-	
 	load_properties ();
-
-	load_pixmaps ();
-
+	clear_board ();
+	window = create_window ();
 	gtk_widget_show (window);
 
-	if (session_xpos >= 0 && session_ypos >= 0) {
-		gdk_window_move (window->window, session_xpos, session_ypos);
-	}
-
-	buffer_pixmap = gdk_pixmap_new (drawing_area->window,
-					BOARDWIDTH, BOARDHEIGHT, -1);
-
-	set_bg_color ();
-
-	init_new_game ();
+	set_sound ();
+	b_timer = g_timer_new ();
+	w_timer = g_timer_new ();
 
+	gui_message (_("Welcome to Iagno!"));
 	gtk_main ();
-
-	g_object_unref (program);
-
 	return 0;
 }
-
Index: gnome-games/iagno/gnothello.h
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/gnothello.h,v
retrieving revision 1.24
diff -u -r1.24 gnothello.h
--- gnome-games/iagno/gnothello.h	5 Jan 2006 07:27:54 -0000	1.24
+++ gnome-games/iagno/gnothello.h	23 Aug 2006 22:07:59 -0000
@@ -1,6 +1,5 @@
 /*
- * gnothello.h - Header for gnothello.c
- * written by Ian Peters <itp@gnu.org>
+ * gnothello.h
  *
  * 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
@@ -22,53 +21,64 @@
 #ifndef _GNOTHELLO_H_
 #define _GNOTHELLO_H_
 
-#define BLACK_TURN 1
-#define WHITE_TURN 31
-#define PIXMAP_FLIP_DELAY 20
-#define PIXMAP_STAGGER_DELAY 3
-#define COMPUTER_MOVE_DELAY 1000
-
-#define OTHER_PLAYER(w) (((w) == WHITE_TURN) ? BLACK_TURN : WHITE_TURN)
-
-#define TILEWIDTH   60
-#define TILEHEIGHT  60
-#define GRIDWIDTH   1
-#define BOARDWIDTH  ((TILEWIDTH+GRIDWIDTH)  * 8)
-#define BOARDHEIGHT ((TILEHEIGHT+GRIDWIDTH) * 8)
-
-void new_game_cb (GtkWidget *widget, gpointer data);
-void new_net_game_cb (GtkWidget *widget, gpointer data);
-void quit_game_cb (GtkWidget *widget, gpointer data);
-void undo_move_cb (GtkWidget *widget, gpointer data);
-void redo_move_cb (GtkWidget *widget, gpointer data);
-void black_level_cb (GtkWidget *widget, gpointer data);
-void white_level_cb (GtkWidget *widget, gpointer data);
-void about_cb (GtkWidget *widget, gpointer data);
-void comp_black_cb (GtkWidget *widget, gpointer data);
-void comp_white_cb (GtkWidget *widget, gpointer data);
-void quick_moves_cb (GtkWidget *widget, gpointer data);
-void anim_cb (GtkWidget *widget, gpointer data);
-void anim_stagger_cb (GtkWidget *widget, gpointer data);
-void load_tiles_cb (GtkWidget *widget, gpointer data);
-void set_selection (GtkWidget *widget, void *data);
-void free_str (GtkWidget *widget, void *data);
-void load_tiles_callback (GtkWidget *widget, void *data);
-void cancel (GtkWidget *widget, void *data);
-gint expose_event (GtkWidget *widget ,GdkEventExpose *event);
-gint configure_event (GtkWidget *widget, GdkEventConfigure *event);
-gint button_press_event (GtkWidget *widget, GdkEventButton *event);
-void gui_draw_pixmap(gint which, gint x, gint y);
-void gui_draw_pixmap_buffer (gint which, gint x, gint y);
-gint flip_pixmaps (gpointer data);
-void init_new_game (void);
-void clear_board (void);
-void create_window (void);
-void gui_status (void);
-void gui_message (gchar *message);
-guint check_computer_players (void);
-void load_pixmaps (void);
-void properties_cb (GtkWidget *widget, gpointer data);
+#define BEST       54
+#define VICTORY    20
+#define PERFECT    18
+#define MAX_DEPTH   8
+
+#define BLACK_TURN   1
+#define WHITE_TURN  31
+#define BLANK      127
+#define OUTSIDE (BLACK_TURN + WHITE_TURN)
+#define OTHER_PLAYER(who) (OUTSIDE - who)
+
+#define BOARD_SIZE    567
+#define BOARD_MIN     279
+#define BOARD_W_MAX  1295
+#define BOARD_H_MAX   825
+#define GRIDWIDTH       1
+
+#define PIXMAP_FLIP_DELAY      32
+#define PIXMAP_STAGGER_DELAY    3
+#define COMPUTER_MOVE_DELAY  1000
+
+#define KEY_BLACK_LEVEL        "/apps/iagno/black_level"
+#define KEY_WHITE_LEVEL        "/apps/iagno/white_level"
+#define KEY_QUICK_MOVES        "/apps/iagno/quick_moves"
+#define KEY_ANIMATE            "/apps/iagno/animate"
+#define KEY_ANIMATE_STAGGER    "/apps/iagno/animate_stagger"
+#define KEY_SHOW_GRID          "/apps/iagno/show_grid"
+#define KEY_FLIP_FINAL_RESULTS "/apps/iagno/flip_final_results"
+#define KEY_FAST_CPU           "/apps/iagno/fast_cpu"
+#define KEY_TILESET            "/apps/iagno/tileset"
+#define KEY_BG_COLOR           "/apps/iagno/bg_color_name"
+#define KEY_BOARD_WIDTH        "/apps/iagno/board_width"
+#define KEY_BOARD_HEIGHT       "/apps/iagno/board_height"
+
+gint clamp_int (gint input, gint low, gint high);
+
+void set_board_size (void);
+
 void set_bg_color (void);
-void gui_draw_grid (void);
+
+void load_pixmaps (void);
+
+void redraw_board (void);
+
+void gui_message (gchar *message);
+
+void clear_board (void);
+
+void init_new_game (void);
+
+void set_flip_pixmaps_id (void);
+
+gboolean check_valid_moves (void);
+
+gboolean check_computer_players (void);
+
+gboolean move (guint x, guint y);
+
+void on_head_button_clicked (GtkToolButton *toolbutton, gpointer user_data);
 
 #endif
Index: gnome-games/iagno/network.c
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/network.c,v
retrieving revision 1.19
diff -u -r1.19 network.c
--- gnome-games/iagno/network.c	23 Feb 2006 07:06:53 -0000	1.19
+++ gnome-games/iagno/network.c	23 Aug 2006 22:07:59 -0000
@@ -1,5 +1,5 @@
 /*
- * Network.c - network code for iagno.
+ * network.c - network code for iagno.
  *
  * 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
@@ -29,130 +29,159 @@
 #include <netinet/in.h>
 #include <errno.h>
 #include <netdb.h>
-#include "othello.h"
+
 #include "gnothello.h"
+#include "properties.h"
+#include "network.h"
 #include "games-network.h"
 #include "games-network-dialog.h"
-#include "network.h"
 
-char *game_server = "localhost"; 
+char *game_server = "localhost";
 char *game_port = "26478";
+guint network_id;
+
+extern gint t_computer_level[2];
 
 static void game_handle_input (NetworkGame *ng, char *buf);
 
 void
 network_start (void)
 {
-  games_network_start();
+	games_network_start ();
 }
 
 void
 network_stop (void)
 {
-  games_network_stop ();
+	games_network_stop ();
 }
 
 gboolean
 is_network_running (void)
 {
-  return (get_network_status () == CONNECTED);
+	return (get_network_status () == CONNECTED);
 }
 
-int
-game_move (guint x, guint y, guint me)
+static gboolean
+network_check (void)
 {
-  static char msgbuf[256];
-
-  gnome_triggers_do ("", NULL, "gnothello", "flip-piece", NULL);
-
-  snprintf (msgbuf, sizeof (msgbuf), "move %u %u %u\n", x, y, me);
+	if (is_network_running())
+		return TRUE;
+	gui_message (_("network is disconnected"));
+	network_stop ();
+	return FALSE;
+}
 
-  games_send_gamedata(msgbuf);
+gboolean
+game_move (guint x, guint y, guint who)
+{
+	static char msgbuf[256];
 
-  return move (x, y, me);
+	gnome_triggers_do ("", NULL, "gnothello", "flip-piece", NULL);
+	snprintf (msgbuf, sizeof (msgbuf), "move %u %u %u\n", x, y, who);
+	games_send_gamedata (msgbuf);
+	return move (x, y);
 }
 
 int
 network_allow (void)
 {
-  return games_network_allow ();
+	return games_network_allow ();
 }
 
 
 void
 network_new (GtkWidget *parent_window)
 {
-  set_game_input_cb (game_handle_input);
-  set_game_clear_cb (clear_board);
-  set_game_msg_cb (gui_message);
-  games_network_new (game_server, game_port, parent_window);
+	set_game_input_cb (game_handle_input);
+	set_game_clear_cb (redraw_board);
+	set_game_msg_cb (gui_message);
+	games_network_new (game_server, game_port, parent_window);
 }
 
 
-static void 
+static void
 game_handle_input (NetworkGame *ng, char *buf)
 {
-  char *args;
+	char *args;
 
-  args = strchr (buf, ' ');
+	args = strchr (buf, ' ');
 
-  if (args) {
-    *args = '\0';
-    args++;
-  }
-
-  if (!strcmp (buf, "set_peer")) {
-    int me;
-      
-    if (ng->mycolor) {
-      network_set_status (ng, DISCONNECTED, _("Invalid move attempted"));
-      return;
-    }
-      
-    if (!args || sscanf (args, "%d", &me) != 1
-        || (me != WHITE_TURN && me != BLACK_TURN)) {
-      network_set_status (ng, DISCONNECTED, _("Invalid game data (set_peer)"));
-      return;
-    }
-    white_level_cb (NULL, "0");
-    black_level_cb (NULL, "0");
-      
-    ng->mycolor = me;
-    network_gui_message (_("Peer introduction complete"));
-  } else if (! strcmp (buf, "move")) {
-    int x, y, me;
-
-    if (!args || sscanf(args, "%d %d %d", &x, &y, &me) != 3
-        || !me || me != (32-ng->mycolor)
-        || x >= 8 || y >= 8) {
-      network_set_status (ng, DISCONNECTED, _("Invalid game data (move)"));
-      return;
-    }
-
-    move (x, y, me);
-  } else if (!strcmp(buf, "new_game")) {
-
-    if (!ng->sent_newgame) {
-      g_string_append_printf (ng->outbuf, "new_game %s \n", player_name);
-    } else {
-      network_gui_connected();
-      network_gui_message (_("New game ready to be started"));
-      network_gui_add_player(args);
-    }
-    ng->sent_newgame = 0;
-
-    whose_turn = BLACK_TURN;
-  } else if (!strcmp(buf, "start_game")) {
-    network_gui_message (_("New game started"));
-                                                                                
-    if (!ng->sent_startgame) {
-      g_string_append_printf (ng->outbuf, "start_game\n");
-    }
-
-    ng->sent_startgame = 0;
-                                                                                
-    init_new_game ();
-    network_gui_close();
-  }
+	if (args)
+	{
+		*args = '\0';
+		args++;
+	}
+
+	if (!strcmp (buf, "set_peer"))
+	{
+		int me;
+
+		if (ng->mycolor)
+		{
+			network_set_status (ng, DISCONNECTED,
+					_("Invalid move attempted"));
+			return;
+		}
+
+		if (!args || sscanf (args, "%d", &me) != 1
+		    || (me != WHITE_TURN && me != BLACK_TURN))
+		{
+			network_set_status (ng, DISCONNECTED,
+					_("Invalid game data (set_peer)"));
+			return;
+		}
+
+		t_computer_level[0] = 0;
+		t_computer_level[1] = 0;
+		apply_changes ();
+		save_properties ();
+
+		ng->mycolor = me;
+		network_gui_message (_("Peer introduction complete"));
+	}
+	else if (!strcmp (buf, "move"))
+	{
+		int x, y, me;
+
+		if (!args || sscanf (args, "%d %d %d", &x, &y, &me) != 3
+		    || me != OTHER_PLAYER (ng->mycolor)
+		    || x > 8 || x < 1 || y > 8 || y < 1)
+		{
+			network_set_status (ng, DISCONNECTED,
+					 _("Invalid game data (move)"));
+			return;
+		}
+
+		move (x, y);
+	}
+	else if (!strcmp (buf, "new_game"))
+	{
+
+		if (!ng->sent_newgame)
+			g_string_append_printf (
+					ng->outbuf, "new_game %s \n", player_name);
+		else
+		{
+			network_gui_connected ();
+			network_gui_message (_("New game ready to be started"));
+			network_gui_add_player (args);
+		}
+		ng->sent_newgame = 0;
+
+		whose_turn = BLACK_TURN;
+	}
+	else if (!strcmp (buf, "start_game"))
+	{
+		network_gui_message (_("New game started"));
+
+		if (!ng->sent_startgame)
+			g_string_append_printf (ng->outbuf, "start_game\n");
+
+		ng->sent_startgame = 0;
+
+		init_new_game ();
+		network_gui_close ();
+		network_id = g_timeout_add (1000,(GSourceFunc)network_check,NULL);
+	}
 }
-
Index: gnome-games/iagno/network.h
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/network.h,v
retrieving revision 1.7
diff -u -r1.7 network.h
--- gnome-games/iagno/network.h	27 Sep 2004 07:48:10 -0000	1.7
+++ gnome-games/iagno/network.h	23 Aug 2006 22:07:59 -0000
@@ -1,16 +1,38 @@
+/*
+ * network.h
+ *
+ * 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
+ *
+ * For more details see the file COPYING.
+ */
+
 #ifndef NETWORK_H
 #define NETWORK_H
 
-#define BLACK_TURN 1
-#define WHITE_TURN 31
-
 extern char *game_server;
-extern gint game_move (guint, guint, guint);
-extern int network_allow (void);
-extern void network_new (GtkWidget *parent_window);
+
 extern void network_start (void);
+
 extern void network_stop (void);
+
 extern gboolean is_network_running (void);
 
-#endif
+extern gboolean game_move (guint x, guint y, guint who);
+
+extern int network_allow (void);
 
+extern void network_new (GtkWidget *parent_window);
+
+#endif
Index: gnome-games/iagno/othello.c
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/othello.c,v
retrieving revision 1.44
diff -u -r1.44 othello.c
--- gnome-games/iagno/othello.c	6 Jan 2006 08:07:00 -0000	1.44
+++ gnome-games/iagno/othello.c	23 Aug 2006 22:07:59 -0000
@@ -1,8 +1,5 @@
-/* -*- mode:C; indent-tabs-mode:t; tab-width:4; c-basic-offset:8; -*- */
-
 /*
- * othello.c - Othello support routines for iagno
- * written by Ian Peters <itp@gnu.org>
+ * othello.c - AI code for iagno.
  *
  * 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
@@ -23,701 +20,566 @@
 
 #include <config.h>
 #include <gnome.h>
-#include <string.h>
-#include <games-clock.h>
 
-#include "othello.h"
 #include "gnothello.h"
+#include "othello.h"
 
-#define PERFECT   17
-#define VICTORY   19
-#define BEST      56
-#define MAX_DEPTH  7
-
-#define BLANK 0
-#define OUTSIDE 128
-#define UL -11
-#define UU -10
-#define UR -9
-#define LL -1
-#define RR +1
-#define DL +9
-#define DD +10
-#define DR +11
-#define NDIRS 8
-
-gint8 squares[64] = {44,45,54,55,23,26,73,76,
-                     32,62,37,67,13,16,31,61,
-                     38,68,83,86,14,15,41,51,
-                     48,58,84,85,24,25,42,52,
-                     74,75,47,57,36,63,33,35,
-                     53,66,46,64,34,43,56,65,
-                     12,17,21,71,28,78,82,87,
-                     22,27,72,77,11,18,81,88};
-
-static const gint heuristic[100] = { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-                                     0, 65, -3,  6,  4,  4,  6, -3, 65,  0,
-                                     0, -3,-29,  3,  1,  1,  3,-29, -3,  0,
-                                     0,  6,  3,  5,  3,  3,  5,  3,  6,  0,
-                                     0,  4,  1,  3,  1,  1,  3,  1,  4,  0,
-                                     0,  4,  1,  3,  1,  1,  3,  1,  4,  0,
-                                     0,  6,  3,  5,  3,  3,  5,  3,  6,  0,
-                                     0, -3,-29,  3,  1,  1,  3,-29, -3,  0,
-                                     0, 65, -3,  6,  4,  4,  6, -3, 65,  0,
-                                     0,  0,  0,  0,  0,  0,  0,  0,  0,  0  };
+#define UL    -11
+#define UU    -10
+#define UR     -9
+#define LL     -1
+#define RR     +1
+#define DL     +9
+#define DD    +10
+#define DR    +11
+#define NDIRS   8
+
+guint squares[64] = {
+	44, 45, 54, 55, 23, 26, 73, 76,
+	32, 62, 37, 67, 13, 16, 31, 61,
+	38, 68, 83, 86, 14, 15, 41, 51,
+	48, 58, 84, 85, 24, 25, 42, 52,
+	74, 75, 47, 57, 36, 63, 33, 35,
+	53, 66, 46, 64, 34, 43, 56, 65,
+	12, 17, 21, 71, 28, 78, 82, 87,
+	22, 27, 72, 77, 11, 18, 81, 88
+};
+
+static const gint heuristic[100] = {
+	0,   0,   0, 0, 0, 0, 0,   0,   0, 0,
+	0, 145, -23, 6, 4, 4, 6, -23, 145, 0,
+	0, -23, -65, 3, 2, 2, 3, -65, -23, 0,
+	0,   6,   3, 5, 3, 3, 5,   3,   6, 0,
+	0,   4,   2, 3, 1, 1, 3,   2,   4, 0,
+	0,   4,   2, 3, 1, 1, 3,   2,   4, 0,
+	0,   6,   3, 5, 3, 3, 5,   3,   6, 0,
+	0, -23, -65, 3, 2, 2, 3, -65, -23, 0,
+	0, 145, -23, 6, 4, 4, 6, -23, 145, 0,
+	0,   0,   0, 0, 0, 0, 0,   0,   0, 0
+};
 
 static const gint dirs[] = { UL, UU, UR, LL, RR, DL, DD, DR };
 
-guint flip_final_id = 0;
-gint flip_final;
-
-gint8 board0[100];
-/* This array can probably be a lot smaller (< 600). However, I am absolutely
- * certain that it cannot be more than 1200. So 1200 is what we use. */
-gint8 history[1200];
-gint hpointer;
-gint vsquares[280][2];
-gint vpointer;
-gint s_kind;
+guint board0[100];
+/* This array can probably be a lot smaller (< 300). */
+guint history[600];
+guint hpointer;
+gint  vsquares[280][2];
+guint vpointer;
+guint s_kind;
+guint bcount;
+guint wcount;
 GRand *rgen;
 
-extern guint black_computer_level;
-extern guint white_computer_level;
+guint move_count;
+guint whose_turn;
 
-extern gint animate;
-extern gint animate_stagger;
 extern guint game_in_progress;
-extern gint8 pixmaps[8][8];
 extern gint8 board[8][8];
-extern gint8 move_count;
-extern guint whose_turn;
-extern gint bcount;
-extern gint wcount;
-
-extern guint tiles_to_flip;
+extern gboolean fast_cpu;
 
 /* Initialization of data */
 void
-init ( void )
+init (void)
 {
-    gint i,j;
-    gint x;
-
-    rgen = g_rand_new ();
+	guint i, j, ij;
 
-    x = 0;
-    for( j = 0; j < 10; j++ )
-        for( i = 0; i < 10; i++ )
-            {
-                if      ( j == 0 || j ==9  ) board0[x] = OUTSIDE;
-                else if ( i == 0 || i == 9 ) board0[x] = OUTSIDE;
-                else                         board0[x] = BLANK;
-                x++;
-            }
-
-    board0[ 44 ] = WHITE_TURN;
-    board0[ 45 ] = BLACK_TURN;
-    board0[ 54 ] = BLACK_TURN;
-    board0[ 55 ] = WHITE_TURN;
+	rgen = g_rand_new ();
 
-    hpointer = 0;
-    vpointer = 0;
+	ij = 0;
+	for (i = 0; i < 10; i++)
+		for (j = 0; j < 10; j++)
+		{
+			if (i == 0 || i == 9)
+				board0[ij] = OUTSIDE;
+			else if (j == 0 || j == 9)
+				board0[ij] = OUTSIDE;
+			else
+				board0[ij] = BLANK;
+			ij++;
+		}
+
+	board0[44] = WHITE_TURN;
+	board0[45] = BLACK_TURN;
+	board0[54] = BLACK_TURN;
+	board0[55] = WHITE_TURN;
+
+	hpointer = 0;
+	vpointer = 0;
+	move_count = 4;
+	whose_turn = BLACK_TURN;
+	bcount = 2;
+	wcount = 2;
 }
 
 /* Copy data from board0 to board */
 void
-board_copy ( void )
+copy_board (void)
 {
-    gint i,j;
+	guint i, j;
 
-    for ( j = 0; j < 8; j++ )
-        for ( i = 0; i < 8; i++ )
-            board[ i ][ j ] = board0[ ( j + 1 ) * 10 + i + 1 ];
+	for (i = 0; i < 8; i++)
+		for (j = 0; j < 8; j++)
+			board[i][j] = (gint8) board0[(i + 1) * 10 + j + 1];
 }
 
 /* Check the validity of the move in a given direction. */
-static
-gint
-is_valid0 (gint xy, gint dir, gint who)
+static gboolean
+is_valid0 (guint yx, gint dir, guint who)
 {
-    gint tmp;
-    gint8 not_me;
-
-    not_me = OTHER_PLAYER (who);
+	guint tmp, not_me;
 
-    /* To be valid, the next counter should not be the current player ... */
-    tmp = xy + dir;
-    if ( board0[tmp] != not_me )
-            return FALSE;
+	not_me = OTHER_PLAYER (who);
 
-    /* ... but eventually we must find a counter that is. */
-    do { tmp += dir; } while ( board0[tmp] == not_me );
+	/* To be valid, the next counter should not be the current player ... */
+	tmp = yx + dir;
+	if (board0[tmp] != not_me)
+		return FALSE;
+
+	/* ... but eventually we must find a counter that is. */
+	do
+	{
+		tmp += dir;
+	}
+	while (board0[tmp] == not_me);
 
-    return board0[tmp] == who;
+	return board0[tmp] == who;
 }
 
 /* Check if a given (empty) square can provide a valid move */
-static
-gint
-is_valid (gint xy, gint who)
+static gboolean
+is_valid (guint yx, guint who)
 {
-    int i;
+	guint i;
 
-    for (i=0; i<NDIRS; i++)
-            if ( is_valid0( xy, dirs[i], who ) ) return( TRUE );
+	for (i = 0; i < NDIRS; i++)
+		if (is_valid0 (yx, dirs[i], who))
+			return (TRUE);
 
-    return FALSE;
+	return FALSE;
 }
 
 /* Check whether the supplied move is a valid one. */
-gint
-is_valid_move (guint x, guint y, guint who) {
-    gint xy;
-
-    xy = ( y + 1 ) * 10 + x + 1;
-    if ( board0[ xy ] != BLANK )
-            return FALSE;
-
-    return is_valid (xy, who);
-}
-
-static
-void
-move_board0 (gint xy, gint dir)
+gboolean
+is_valid_move (guint x, guint y, guint who)
 {
-    gint8 tmp;
-    guint not_me;
+	guint yx;
 
-    not_me = OTHER_PLAYER (whose_turn);
-    tmp = xy + dir;
-    if ( board0[ tmp ] != not_me )
-            return;
-    /* Find the extent of the move in direction dir. */
-    do { tmp += dir; } while ( board0[ tmp ] == not_me );
-    if ( board0[tmp] != whose_turn )
-            return;
-
-    /* Now walk back to where we started flipping pieces over. */
-    tmp -= dir;
-    while ( tmp != xy )
-        {
-            board0[tmp] = whose_turn;     /* Flip pieces */
-            history[ hpointer++ ] = tmp;  /* Record history */
-            tmp -= dir;
-        }
+	yx = y * 10 + x;
+	if (board0[yx] != BLANK)
+		return FALSE;
+
+	return is_valid (yx, who);
+}
+
+static void
+move_board0 (guint yx, gint dir)
+{
+	guint tmp;
+	guint not_me;
+
+	not_me = OTHER_PLAYER (whose_turn);
+	tmp = yx + dir;
+	if (board0[tmp] != not_me)
+		return;
+	/* Find the extent of the move in direction dir. */
+	do
+	{
+		tmp += dir;
+	}
+	while (board0[tmp] == not_me);
+	if (board0[tmp] != whose_turn)
+		return;
+
+	/* Now walk back to where we started flipping pieces over. */
+	tmp -= dir;
+	while (tmp != yx)
+	{
+		board0[tmp] = whose_turn;	/* Flip pieces    */
+		history[hpointer++] = tmp;	/* Record history */
+		tmp -= dir;
+	}
 }
 
 /* reverse some pieces */
 void
-move_board (gint xy)
+move_board (guint yx)
 {
-    gint tmp, count;
-    int i;
-
-    count = hpointer;
-
-    for (i=0; i<NDIRS; i++)
-            move_board0( xy, dirs[i] );
-
-    board0[xy] = whose_turn;
-    count = hpointer-count;
-    history[ hpointer++ ] = count;     /* make history */
-    history[ hpointer++ ] = whose_turn;
-
-    if ( whose_turn == WHITE_TURN )
-        {
-            wcount += count+1;
-            bcount -= count;
-        }
-    else
-        {
-            bcount += count+1;
-            wcount -= count;
-        }
-    tmp = squares[move_count];
-    squares[move_count++] = xy;
-    if ( tmp != xy)
-        {
-            count = move_count;
-            while ( squares[count] != xy ) count++;
-            squares[count] = tmp;
-        }
-    whose_turn = OTHER_PLAYER (whose_turn);
-}
-
+	guint count, i, tmp;
 
-gint
-move (guint x, guint y, guint me)
-{
-    gint tmp;
+	count = hpointer;
 
-    tmp = (gint)( ( y + 1 ) * 10 + x + 1 );
-    if ( board0[ tmp ] != BLANK )
-            return FALSE;
-    if ( !is_valid( tmp, whose_turn ) )
-            return FALSE;
-    move_board( tmp );
-    board_copy();
-
-    pixmaps[ x ][ y ] = (gint8)me;
-    gui_draw_pixmap( me, x, y );
-
-    if ( whose_turn == BLACK_TURN )
-        {
-            gui_message(_("Dark's move"));
-        }
-    else if ( whose_turn == WHITE_TURN )
-        {
-            gui_message(_("Light's move"));
-        }
-
-    gui_status();
-
-    tiles_to_flip = 1;
-    check_valid_moves();
-    check_computer_players();
+	for (i = 0; i < NDIRS; i++)
+		move_board0 (yx, dirs[i]);
 
-    return FALSE;
+	board0[yx] = whose_turn;
+	count = hpointer - count;
+	history[hpointer++] = count;	/* history[t1,t2,,,tn, n,who] */
+	history[hpointer++] = whose_turn;
+	if (whose_turn == WHITE_TURN)
+	{
+		wcount += count + 1;
+		bcount -= count;
+	}
+	else
+	{
+		bcount += count + 1;
+		wcount -= count;
+	}
+	i = move_count++;		/* increase move_count */
+	tmp = squares[i];	    /* squares[0,1,2,3.,,move_count,,,62,63] */
+	squares[i] = yx;		/*        [-already puted-|-yet blank--] */
+	if (tmp != yx)			/* sort squares */
+	{
+		while (squares[++i] != yx);
+		squares[i] = tmp;
+	}
+	whose_turn = OTHER_PLAYER (whose_turn);
 }
 
 /* Back to before board0 */
 void
-undo ( void )
+back (void)
 {
-    gint8 not_me, count;
+	guint count, not_me;
 
-    whose_turn = history[ --hpointer ];     /* history[t1,t2,,,tn, n,who] */
-    count = history[ --hpointer ];
+	whose_turn = history[--hpointer];	/* history[t1,t2,,,tn, n,who] */
+	count = history[--hpointer];
 
-    if ( whose_turn == WHITE_TURN )
-        {
-            wcount -= count+1;
-            bcount += count;
-        }
-    else
-        {
-            bcount -= count+1;
-            wcount += count;
-        }
-
-    board0[ squares[ --move_count ]] = BLANK;  /* decrease move_count    */
-
-    not_me = OTHER_PLAYER (whose_turn);
-    while ( count > 0 )
-        {
-            board0[ history[ --hpointer ] ] = not_me;
-            count--;
-        }
+	if (whose_turn == WHITE_TURN)
+	{
+		wcount -= count + 1;
+		bcount += count;
+	}
+	else
+	{
+		bcount -= count + 1;
+		wcount += count;
+	}
+
+	board0[squares[--move_count]] = BLANK;	/* decrease move_count    */
+
+	not_me = OTHER_PLAYER (whose_turn);
+	while (count > 0)
+	{
+		board0[history[--hpointer]] = not_me;
+		count--;
+	}
 }
 
 /* Sort vsquares by small order */
-static
-void
-sort (gint l, gint r)
-{
-    gint i, j, v, w, x;
-
-    i = l; j = r;
-    x = vsquares[ ( l + r ) / 2 ][ 1 ];
-    do
-        {
-            while ( vsquares[ i ][ 1 ] < x ) i++;
-            while ( x < vsquares[ j ][ 1 ] ) j--;
-            if ( i < j )
-                {
-                    v = vsquares[ i ][ 0 ];
-                    w = vsquares[ i ][ 1 ];
-                    vsquares[ i ][ 0 ] = vsquares[ j ][ 0 ];
-                    vsquares[ i ][ 1 ] = vsquares[ j ][ 1 ];
-                    vsquares[ j ][ 0 ] = v;
-                    vsquares[ j ][ 1 ] = w;
-                }
-            if ( i <= j )
-                {
-                    i++;
-                    j--;
-                }
-        } while ( i <= j );
-
-    if ( l < j ) sort( l, j );
-    if ( i < r ) sort( i, r );
-}
-
-static
-gint
-eval_heuristic( void )
-{
-    gint8 i, xy;
-    gint count = 0;
-
-    for ( i = 0; i < move_count; i++ )
-        {
-            xy = squares[ i ];
-            count = ( board0[ xy ] == whose_turn ) ?
-                    count + heuristic[ xy ] : count - heuristic[ xy ];
-        }
-
-    return count;
-}
-
-static
-gint
-mobility( void )
-{
-    gint8 i, xy;
-    gint count = 0;
-
-    for ( i = move_count; i < 64; i++ )
-        {
-            xy = squares[ i ];
-            if ( is_valid( xy, whose_turn ) ) count++;
-        }
-
-    return count;
-}
-
-static
-gint
-around0(gint xy)
+static void
+sort (guint l, guint r)
 {
-    gint count = 0;
-    int i;
-
-    for (i=0; i<NDIRS; i++)
-            if ( board0[ xy + dirs[i] ] == BLANK ) count--;
+	guint i, j;
+	gint v, w, x;
 
-    if ( !count ) count = 2;
-
-    return count;
-}
-
-static
-gint
-around( void )
-{
-    gint8 i, xy;
-    gint count = 0;
-
-    for ( i = 0 ; i < move_count; i++ )
-        {
-            xy = squares[ i ];
-            count = ( board0[ xy ] == whose_turn ) ?
-                count + around0( (gint) xy ) : count - around0( (gint) xy );
-        }
-
-    return count;
-}
-
-/* Evaluate the board   */
-static
-gint
-b_evaluation( void )
-{
-    gint score1, score2, score3;
-
-    score1 = mobility();
-    whose_turn = OTHER_PLAYER (whose_turn);
-    score1 -= mobility();
-    whose_turn = OTHER_PLAYER (whose_turn);
-
-    score2 = around();
-    score3 = eval_heuristic();
-
-    return score1 + score2 + score3;
+	i = l;
+	j = r;
+	x = vsquares[(l + r) / 2][1];
+	do
+	{
+		while (vsquares[i][1] < x)
+			i++;
+		while (x < vsquares[j][1])
+			j--;
+		if (i < j)
+		{
+			v = vsquares[i][0];
+			w = vsquares[i][1];
+			vsquares[i][0] = vsquares[j][0];
+			vsquares[i][1] = vsquares[j][1];
+			vsquares[j][0] = v;
+			vsquares[j][1] = w;
+		}
+		if (i <= j)
+		{
+			i++;
+			j--;
+		}
+	}
+	while (i <= j);
+
+	if (l < j)
+		sort (l, j);
+	if (i < r)
+		sort (i, r);
+}
+
+static gint
+eval_heuristic (void)
+{
+	guint i, yx;
+	gint count = 0;
+
+	for (i = 0; i < move_count; i++)
+	{
+		yx = squares[i];
+		if (board0[yx] == whose_turn)
+			count += heuristic[yx];
+		else
+			count -= heuristic[yx];
+	}
+
+	return count;
+}
+
+gint
+mobility (guint who)
+{
+	guint i, yx;
+	gint count = 0;
+
+	for (i = move_count; i < 64; i++)
+	{
+		yx = squares[i];
+		if (is_valid (yx, who))
+			count++;
+	}
+
+	return count;
+}
+
+static gint
+around0 (guint yx)
+{
+	guint i;
+	gint count = 0;
+
+	for (i = 0; i < NDIRS; i++)
+		if (board0[yx + dirs[i]] == BLANK)
+			count--;
+
+	if (!count)
+		count = 2;
+
+	return count;
+}
+
+static gint
+around (void)
+{
+	guint i, yx;
+	gint count = 0;
+
+	for (i = 0; i < move_count; i++)
+	{
+		yx = squares[i];
+		if (board0[yx] == whose_turn)
+			count += around0 (yx);
+		else
+			count -= around0 (yx);
+	}
+
+	return count;
+}
+
+/* Best evaluation */
+static gint
+b_evaluation (void)
+{
+	gint score1, score2, score3;
+
+	score1 = mobility (whose_turn);
+	score1 -= mobility (OTHER_PLAYER (whose_turn));
+	score2 = around ();
+	score3 = eval_heuristic ();
+	return score1 * 2 + score2 + score3 / 2;
 }
 
 /* Victory evaluation */
-static
-gint
-v_evaluation( void )
-{
-    gint aa;
-
-    aa = wcount - bcount;
-    if ( whose_turn == BLACK_TURN ) aa = -aa;
-
-    if ( aa > 0 ) return  1;    /* win  */
-    if ( aa < 0 ) return -1;    /* lose */
-    return 0;                   /* draw */
-}
-
-static
-gint
-p_evaluation( void )
+static gint
+v_evaluation (void)
 {
+	gint aa;
 
-    if ( whose_turn == WHITE_TURN )
-            return wcount - bcount;
+	aa = wcount - bcount;
+	if (whose_turn == BLACK_TURN)
+		aa = -aa;
 
-    return bcount - wcount;
+	if (aa > 0)
+		return 1;	/* win  */
+	if (aa < 0)
+		return -1;	/* lose */
+	return 0;		/* draw */
 }
 
-static
-gint
-w_evaluation( void )
+/* Perfect evaluation */
+static gint
+p_evaluation (void)
 {
-    gint aa;
-
-    if ( !bcount || !wcount )
-        {
-            if ( whose_turn == WHITE_TURN && !bcount )   return 10000;
-            if ( whose_turn == BLACK_TURN && !wcount )   return 10000;
-            return -10000;
-        }
-
-    aa = wcount - bcount;
-    if ( whose_turn == BLACK_TURN ) aa = -aa;
-
-    if ( aa > 0 ) return aa + 100;
-    if ( aa < 0 ) return aa - 100;
-    return( 0 );
+	if (whose_turn == WHITE_TURN)
+		return wcount - bcount;
+	return bcount - wcount;
 }
 
-/* alpha-beta search */
-static
-gint
-search(gint n, gint a, gint b)
+/* Win evaluation under best search */
+static gint
+w_evaluation (void)
 {
-    gint aa, bb, xy, i, j;
+	gint aa;
 
-    if ( !n )
-    {
-        switch (s_kind)
-                {
-                    case PERFECT:
-                            return( p_evaluation() );
-                    case VICTORY:
-                            return( v_evaluation() );
-                    default:
-                            return( b_evaluation() );
-                }
-        }
-
-    aa = a;
-
-    j = vpointer;
-    for ( i = (gint)move_count ; i < 64 ; i++ )
-        {                                           /* entry valid squares */
-            xy = (gint)squares[ i ];
-            if ( is_valid( xy, whose_turn ) )
-                {
-                    vsquares[ ++j ][ 0 ] = xy;
-                    move_board( xy );
-                    vsquares[ j ][ 1 ] = mobility();
-                    undo();
-                }
-        }
-
-    if ( j == vpointer )                           /* pass ?  */
-        {
-            whose_turn = ( whose_turn == WHITE_TURN ) ? BLACK_TURN : WHITE_TURN;
-            if ( !mobility() )
-                {
-                    whose_turn = OTHER_PLAYER (whose_turn);
-
-                    switch ( s_kind )
-                        {
-                            case PERFECT:       return( p_evaluation() );
-                            case VICTORY:       return( v_evaluation() );
-                            default:            return( w_evaluation() );
-                        }
-                }
-            aa = -search( n, -b, -aa );
-            whose_turn = OTHER_PLAYER (whose_turn);
-            vsquares[ j ][ 0 ] = 0;        /* mark pass              */
-            return aa;
-        }
-
-    sort( vpointer + 1, j );
-
-    i = vpointer;                          /* save old vpointer      */
-    vpointer = j + 1;                      /* new vpointer           */
-
-    j = i + 1;
-    while ( aa < b && j < vpointer )
-        {
-            xy = vsquares[ j ][ 0 ];
-            move_board( xy );
-            bb = -search( n - 1, -b, -aa ); /* evaluate this square  */
-            undo();
-            if ( aa < bb )
-                {
-                    aa = bb;
-                    vsquares[ i ][ 0 ] = xy;   /* save this square       */
-                }
-            j++;
-        }
-    vpointer = i;                          /* pop vpointer           */
-    return aa;
-}
+	aa = wcount - bcount;
+	if (whose_turn == BLACK_TURN)
+		aa = -aa;
 
-static
-void
-random_select( void )
-{
-    gint xy, i, j;
+	if (!bcount || !wcount)
+	{
+		if (aa > 0)
+			return aa + 10000;
+		return aa - 10000;
+	}
 
-    vsquares[ 0 ][ 0 ] = 0;
-    j = 0;
-    for ( i = move_count ; i < 64 ; i++ )
-        {
-            xy = squares[ i ];
-            if ( is_valid( xy, whose_turn ) )
-                    vsquares[ j++ ][ 0 ] = xy;
-        }
-    if ( j )
-        {
-            i = g_rand_int_range (rgen, 0, j);
-            vsquares[ 0 ][ 0 ] = vsquares[ i ][ 0 ];
-        }
+	if (aa > 0)
+		return aa + 1000;
+	if (aa < 0)
+		return aa - 1000;
+	return 0;
 }
 
-static
-gint
-computer_move (gint level)
-{
-    gint nn, aa, kind, best_xy;
-
-    vsquares[ 0 ][ 0 ] = -1;
-    nn = 64 - move_count;
-    if  ( nn > BEST )  random_select();
-    else
-        {
-            if ( nn <= PERFECT - level )
-                { kind = PERFECT;  aa = 127; }
-            if ( PERFECT - level < nn && nn <= VICTORY - level )
-                { kind = VICTORY;  aa = 2;   }
-            if ( VICTORY - level < nn && nn <= BEST )
-                { kind = BEST;     aa = 32767;   nn = MAX_DEPTH - level; }
-            s_kind = kind;
-            vsquares[ 0 ][ 1 ] = search( nn, -aa, aa );
-        }
-
-    best_xy = vsquares[ 0 ][ 0 ];
-
-    if ( best_xy == -1 )    /* If I can't win, then search the best again. */
-        {
-            s_kind = BEST;
-            vsquares[ 0 ][ 1 ] = search( MAX_DEPTH - level, -32767, 32767 );
-            best_xy = vsquares[ 0 ][ 0 ];
-        }
-
-    if ( best_xy )
-        move ( best_xy % 10 - 1, best_xy / 10 - 1, whose_turn );
-
-    return FALSE;
-}
-
-gint
-computer_move_1 (guint me)
-{
-    return computer_move( 6 );
-}
-
-gint
-computer_move_2 (guint me)
-{
-    return computer_move( 4 );
-}
-
-gint
-computer_move_3 (guint me)
+/* alpha-beta search */
+static gint
+search (guint n, gint a, gint b)
 {
-    return computer_move( 2 );
-}
+	guint i, j, yx;
+	gint aa, bb;
 
-gint
-computer_move_4 (guint me)
-{
-    return computer_move( 0 );
+	if (!n)					/* end ? */
+	{
+		switch (s_kind)
+		{
+			case PERFECT:
+				return p_evaluation ();
+			case VICTORY:
+				return v_evaluation ();
+			default:
+				return b_evaluation ();
+		}
+	}
+
+	aa = a;
+	j = vpointer;				/* entry valid squares */
+	for (i = move_count; i < 64; i++)
+	{
+		yx = squares[i];
+		if (is_valid (yx, whose_turn))
+		{
+			vsquares[++j][0] = yx;
+			move_board (yx);
+			vsquares[j][1] = mobility (whose_turn);	/* simple evaluation */
+			back ();
+		}
+	}
+
+	if (j == vpointer)			/* pass ? */
+	{
+		whose_turn = OTHER_PLAYER (whose_turn);
+		if (!mobility (whose_turn))	/* end ?  */
+		{
+			whose_turn = OTHER_PLAYER (whose_turn);
+			switch (s_kind)
+			{
+				case PERFECT:
+					return p_evaluation ();
+				case VICTORY:
+					return v_evaluation ();
+				default:
+					return w_evaluation ();
+			}
+		}
+
+		aa = -search (n, -b, -aa);
+		whose_turn = OTHER_PLAYER (whose_turn);
+		vsquares[j][0] = 0;		/* mark pass       */
+		return aa;
+	}
+
+	sort (vpointer + 1, j);		/* sort vsquares    */
+	i = vpointer;				/* save vpointer    */
+	vpointer = j + 1;			/* new vpointer     */
+
+	j = i + 1;
+	while (aa < b && j < vpointer)	/* evaluate squares */
+	{
+		yx = vsquares[j][0];
+		move_board (yx);
+		bb = -search (n - 1, -b, -aa);
+		back ();
+		if (aa < bb)
+		{
+			aa = bb;
+			vsquares[i][0] = yx;	/* save this square  */
+		}
+		j++;
+	}
+	vpointer = i;				/* pop vpointer      */
+	return aa;
+}
+
+/* for first 6 turns */
+static void
+random_select (void)
+{
+	guint i, j, yx;
+
+	vsquares[0][0] = 0;
+	j = 0;
+	for (i = move_count; i < 64; i++)
+	{
+		yx = squares[i];
+		if (is_valid (yx, whose_turn))
+			vsquares[j++][0] = yx;
+	}
+	if (j > 1)
+	{
+		i = g_rand_int_range (rgen, 0, j);
+		if (heuristic[vsquares[i][0]] < 0)		/* If the square is critical */
+			i = g_rand_int_range (rgen, 0, j);	/* then select once more,    */
+		vsquares[0][0] = vsquares[i][0];		/* but not three times.      */
+	}
 }
 
 gboolean
-flip_final_results (gpointer data)
+computer_move (guint level)
 {
-    guint i;
-    guint white_pieces;
-    guint black_pieces;
-    guint adder  =  0;
-
-    white_pieces = wcount;
-    black_pieces = bcount;
-
-	i = 0;
-    for ( ; i < black_pieces; i++ )
-        {
-            board[i % 8][i / 8] = BLACK_TURN;
-            if ( pixmaps[i % 8][i / 8] < 1 )
-                    pixmaps[i % 8][i / 8] = WHITE_TURN;
-            if ( pixmaps[i % 8][i / 8] == WHITE_TURN )
-                    {
-                            pixmaps[i % 8][i / 8] += adder;
-                            if (animate_stagger) adder++;
-                    }
-        }
-    for ( ; i < 64 - white_pieces; i++ )
-        {
-            board[i % 8][i / 8] = 0;
-            pixmaps[i % 8][i / 8] = 100;
-        }
-    for ( ; i < 64; i++ )
-        {
-            board[i % 8][i / 8] = WHITE_TURN;
-            if ( pixmaps[i % 8][i / 8] == 0 )
-                    pixmaps[i % 8][i / 8] = BLACK_TURN;
-            if ( pixmaps[i % 8][i / 8] == BLACK_TURN )
-                {
-                    pixmaps[i % 8][i / 8] -= adder;
-                    if ( animate_stagger ) adder++;
-                }
-        }
+	guint depth, nn, kind;
+	gint aa, best_yx, cs;
 
-    tiles_to_flip = 1;
-
-    return FALSE;
-}
-
-gint
-check_valid_moves (void)
-{
-    guint white_moves = 0;
-    guint black_moves = 0;
+	cs = (fast_cpu) ? 0: 1;
+	vsquares[0][0] = -1;
+	depth = clamp_int ((level * 2 - cs), 1, MAX_DEPTH);
+	nn = 64 - move_count;
+	kind = PERFECT;
+	aa = 127;
+	if (nn > BEST)
+		random_select ();
+	else
+	{
+		if (PERFECT - MAX_DEPTH + depth < nn && nn <= VICTORY - MAX_DEPTH + depth)
+		{
+			kind = VICTORY;
+			aa = 2;
+		}
+		if (VICTORY - MAX_DEPTH + depth < nn && nn <= BEST)
+		{
+			kind = BEST;
+			aa = 32767;
+			nn = depth;
+		}
+		s_kind = kind;
+		vsquares[0][1] = search (nn, -aa, aa);
+	}
+
+	best_yx = vsquares[0][0];
+	if (best_yx == -1)	/* If I can't win, then search the best again. */
+	{
+		s_kind = BEST;
+		vsquares[0][1] = search (depth, -32767, 32767);
+		best_yx = vsquares[0][0];
+	}
 
-    if ( !game_in_progress )                                
-            return TRUE;
-    if ( mobility() )                                       
-            return TRUE;
-
-    whose_turn = OTHER_PLAYER (whose_turn);
-
-	if ( !mobility() )
-        {
-            white_moves = wcount;
-            black_moves = bcount;
-            if ( white_moves > black_moves )
-                gui_message (_("Light player wins!"));
-            if ( black_moves > white_moves )
-                gui_message (_("Dark player wins!"));
-            if ( white_moves == black_moves )
-                gui_message (_("The game was a draw."));
-            whose_turn = 0;
-            game_in_progress = 0;
-            if ( flip_final )
-                flip_final_id = g_timeout_add (100, flip_final_results, NULL);
-            return TRUE;
-        }
-
-    if ( whose_turn == BLACK_TURN )
-        {
-            gui_message(_("Light must pass, Dark's move"));
-            return TRUE;
-        }
-
-    if ( whose_turn == WHITE_TURN )
-        {
-            gui_message(_("Dark must pass, Light's move"));
-            return TRUE;
-        }
+	if (game_in_progress && best_yx)		/* not pass ? */
+		return move (best_yx % 10, best_yx / 10);
 
-    return TRUE;
+	return FALSE;
 }
Index: gnome-games/iagno/othello.h
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/othello.h,v
retrieving revision 1.9
diff -u -r1.9 othello.h
--- gnome-games/iagno/othello.h	5 Jan 2006 06:02:21 -0000	1.9
+++ gnome-games/iagno/othello.h	23 Aug 2006 22:07:59 -0000
@@ -1,6 +1,5 @@
 /*
- * othello.h - Header for othello.c
- * written by Ian Peters <itp@gnu.org>
+ * othello.h
  *
  * 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
@@ -22,17 +21,18 @@
 #ifndef _OTHELLO_H_
 #define _OTHELLO_H_
 
-gint is_valid_move (guint, guint, guint);
-gint move (guint, guint, guint);
-void move_board (gint);
-gboolean flip_final_results (gpointer data);
-gint check_valid_moves (void);
-gint computer_move_1 (guint);
-gint computer_move_2 (guint);
-gint computer_move_3 (guint);
-gint computer_move_4 (guint);
 void init (void);
-void board_copy (void);
-void undo (void);
+
+void copy_board (void);
+
+gboolean is_valid_move (guint x, guint y, guint who);
+
+void move_board (guint yx);
+
+void back (void);
+
+gint mobility (guint who);
+
+gboolean computer_move (guint level);
 
 #endif
Index: gnome-games/iagno/properties.c
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/properties.c,v
retrieving revision 1.34
diff -u -r1.34 properties.c
--- gnome-games/iagno/properties.c	6 Jun 2005 22:51:13 -0000	1.34
+++ gnome-games/iagno/properties.c	23 Aug 2006 22:07:59 -0000
@@ -1,7 +1,5 @@
-/* -*- mode:C; indent-tabs-mode:t; tab-width:8; c-basic-offset:8; -*- */
-
 /*
- * Properties.c - Properties and preferences part of iagno
+ * properties.c - interface code for iagno.
  *
  * 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
@@ -21,688 +19,589 @@
  */
 
 #include <config.h>
+#include <stdio.h>
+#include <fcntl.h>
 #include <gnome.h>
-#include <string.h>
 #include <gconf/gconf-client.h>
-#include <games-gconf.h>
-#include <games-frame.h>
-#include <games-files.h>
 
-#include "properties.h"
 #include "gnothello.h"
-#include "othello.h"
-
-#define KEY_TILESET "/apps/iagno/tileset"
-#define KEY_BLACK_LEVEL "/apps/iagno/black_level"
-#define KEY_WHITE_LEVEL "/apps/iagno/white_level"
-#define KEY_QUICK_MOVES "/apps/iagno/quick_moves"
-#define KEY_ANIMATE "/apps/iagno/animate"
-#define KEY_ANIMATE_STAGGER "/apps/iagno/animate_stagger"
-#define KEY_SHOW_GRID "/apps/iagno/show_grid"
-#define KEY_FLIP_FINAL_RESULTS "/apps/iagno/flip_final_results"
-
-
-extern GtkWidget *window;
-extern guint black_computer_level;
-extern guint white_computer_level;
-extern guint computer_speed;
-extern guint black_computer_id;
-extern guint white_computer_id;
-extern gchar *tile_set;
-extern gchar *tile_set_tmp;
-extern gint8 pixmaps[8][8];
-extern gint animate;
-extern gint animate_stagger;
-extern gint flip_pixmaps_id;
-extern gint flip_final;
-extern gint grid;
-
-guint t_black_computer_level;
-guint t_white_computer_level;
-gint t_animate;
-gint t_quick_moves;
-gint t_animate_stagger;
-gint t_flip_final;
-gint t_grid;
-
-static GamesFileList * theme_file_list = NULL;
-
-static void apply_changes (void);
-
-/*
- * FIXME:
- * 	This was only a quick port to gconf.
- *	It doesn't abide by the HIG.
- */
-
-static gint clamp_int (gint input, gint low, gint high)
-{
-        if (input < low)
-                input = low;
-        if (input > high)
-                input = high;
+#include "properties.h"
+#include "network.h"
 
-        return input;
-}
+guint    t_computer_level[2];
+gboolean t_quick_moves;
+guint    t_animate;
+gboolean t_options[5];
+gchar    *t_tile_set;
+gchar    *t_bg_color_name;
+GdkColor t_bg_color = {0,0,0,0};
+
+extern guint8 kifu[61][2];
+
+extern GtkWidget *properties_dialog;
+extern GtkWidget *file_open_dialog;
+extern GtkWidget *file_save_dialog;
+
+extern guint    black_computer_level;
+extern guint    white_computer_level;
+extern gboolean quick_moves;
+extern guint    animate;
+extern gboolean animate_stagger;
+extern gboolean grid;
+extern gboolean flip_final;
+extern gboolean fast_cpu;
+extern gchar    *tile_set;
+extern gchar    *bg_color_name;
+
+extern guint    computer_speed;
+extern guint    flip_speed;
+extern guint    board_width;
+extern guint    board_height;
+extern guint    game_in_progress;
 
-void 
+void
 load_properties (void)
 {
 	GConfClient *client;
-	GError      *error = NULL;
 
 	client = gconf_client_get_default ();
-	if (!games_gconf_sanity_check_string (client, KEY_TILESET)) {
-		exit(1);
-	}
-	black_computer_level = gconf_client_get_int (client, KEY_BLACK_LEVEL, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-        black_computer_level = clamp_int (black_computer_level, 0, 3);
-	
-	white_computer_level = gconf_client_get_int (client, KEY_WHITE_LEVEL, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-        white_computer_level = clamp_int (white_computer_level, 0, 3);
-	
-	if (gconf_client_get_bool (client, KEY_QUICK_MOVES, &error))
-		computer_speed = COMPUTER_MOVE_DELAY / 2;
-	else
-		computer_speed = COMPUTER_MOVE_DELAY;
-
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
 
 	if (tile_set)
 		g_free (tile_set);
-
-	tile_set = gconf_client_get_string (client, KEY_TILESET, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-	if (tile_set == NULL)
-		tile_set = g_strdup ("classic.png");
-	
-	animate = gconf_client_get_int (client, KEY_ANIMATE, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-        animate = clamp_int (animate, 0, 2);
-
-	animate_stagger = gconf_client_get_bool (client, KEY_ANIMATE_STAGGER, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-
-	grid = gconf_client_get_bool (client, KEY_SHOW_GRID, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-
-	flip_final = gconf_client_get_bool (client, KEY_FLIP_FINAL_RESULTS, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-
-	switch (animate) {
-	case 0:
-		flip_pixmaps_id = g_timeout_add (100, flip_pixmaps, &error);
-		break;
-	case 1:
-		flip_pixmaps_id = g_timeout_add (PIXMAP_FLIP_DELAY * 8, flip_pixmaps, NULL);
-		break;
-	default:
-	case 2:
-		flip_pixmaps_id = g_timeout_add (PIXMAP_FLIP_DELAY, flip_pixmaps, NULL);
-		break;
-	}
-
+	if (bg_color_name)
+		g_free (bg_color_name);
+	black_computer_level =clamp_int (
+		gconf_client_get_int (client, KEY_BLACK_LEVEL, NULL), 0, 3);
+	white_computer_level = clamp_int (
+		gconf_client_get_int (client, KEY_WHITE_LEVEL, NULL), 0, 3);
+	quick_moves = gconf_client_get_bool (client, KEY_QUICK_MOVES, NULL);
+	animate = clamp_int (gconf_client_get_int (client, KEY_ANIMATE, NULL),0, 2);
+	animate_stagger = gconf_client_get_bool (client, KEY_ANIMATE_STAGGER, NULL);
+	grid = gconf_client_get_bool (client, KEY_SHOW_GRID, NULL);
+	flip_final = gconf_client_get_bool (client, KEY_FLIP_FINAL_RESULTS, NULL);
+	fast_cpu = gconf_client_get_bool (client, KEY_FAST_CPU, NULL);
+	tile_set = gconf_client_get_string (client, KEY_TILESET, NULL);
+	if (!tile_set)
+		tile_set = g_strdup (_("classic.png"));
+	bg_color_name = gconf_client_get_string (client, KEY_BG_COLOR, NULL);
+	if (!bg_color_name)
+		bg_color_name = g_strdup (_("#0x008C8C00"));
+	board_width = gconf_client_get_int (client, KEY_BOARD_WIDTH, NULL);
+	board_height = gconf_client_get_int (client, KEY_BOARD_HEIGHT, NULL);
+	board_width = clamp_int (board_width, BOARD_MIN, BOARD_W_MAX);
+	board_height = clamp_int (board_height, BOARD_MIN, BOARD_H_MAX);
 	g_object_unref (client);
 }
 
-static void
-reset_properties (void)
+void
+save_properties (void)
 {
 	GConfClient *client;
-	GError      *error = NULL;
 
 	client = gconf_client_get_default ();
 
-	black_computer_level =
-		gconf_client_get_int (client, KEY_BLACK_LEVEL, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-        t_black_computer_level = black_computer_level
-		= clamp_int (black_computer_level, 0, 3);
-
-	white_computer_level =
-		gconf_client_get_int (client, KEY_WHITE_LEVEL, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-        t_white_computer_level = white_computer_level
-		= clamp_int (white_computer_level, 0, 3);
-	
-	t_quick_moves = gconf_client_get_bool (client, KEY_QUICK_MOVES, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-
-	if (tile_set_tmp)
-		g_free (tile_set_tmp);
-
-	tile_set_tmp = gconf_client_get_string (client, KEY_TILESET, &error);
-	if (error) {
-		g_warning (G_STRLOC ": gconf error: %s\n", error->message);
-		g_error_free (error);
-		error = NULL;
-	}
-	if (tile_set_tmp == NULL)
-		tile_set_tmp = g_strdup("classic.png");
-	
-	t_animate         = animate;
-	t_animate_stagger = animate_stagger;
-	t_grid            = grid;
-	t_flip_final      = flip_final;
+	gconf_client_set_int    (client, KEY_BLACK_LEVEL, black_computer_level, NULL);
+	gconf_client_set_int    (client, KEY_WHITE_LEVEL, white_computer_level, NULL);
+	gconf_client_set_bool   (client, KEY_QUICK_MOVES, quick_moves, NULL);
+	gconf_client_set_int    (client, KEY_ANIMATE,     animate, NULL);
+	gconf_client_set_bool   (client, KEY_ANIMATE_STAGGER, animate_stagger, NULL);
+	gconf_client_set_bool   (client, KEY_SHOW_GRID,   grid, NULL);
+	gconf_client_set_bool   (client, KEY_FLIP_FINAL_RESULTS, flip_final, NULL);
+	gconf_client_set_bool   (client, KEY_FAST_CPU,    fast_cpu, NULL);
+	gconf_client_set_string (client, KEY_TILESET,     tile_set, NULL);
+	gconf_client_set_string (client, KEY_BG_COLOR,    bg_color_name, NULL);
 
 	g_object_unref (client);
 }
 
-static void 
-black_computer_level_select (GtkWidget *widget, gpointer data)
-{
-	if ((GPOINTER_TO_INT(data) != t_black_computer_level) 
-	    && (GTK_TOGGLE_BUTTON (widget)->active)) {
-		t_black_computer_level = GPOINTER_TO_INT(data);
-		apply_changes ();
-	}
-}
-
-static void 
-white_computer_level_select (GtkWidget *widget, gpointer data)
+void
+reset_properties (void)
 {
-	if ((GPOINTER_TO_INT(data) != t_white_computer_level)
-	    && (GTK_TOGGLE_BUTTON (widget)->active)) {
-		t_white_computer_level = GPOINTER_TO_INT(data);
-		apply_changes ();
-	}
+	if (t_tile_set)
+		g_free (t_tile_set);
+	if (t_bg_color_name)
+		g_free (t_bg_color_name);
+	t_computer_level[0] = black_computer_level;
+	t_computer_level[1] = white_computer_level;
+	t_animate = animate;
+	t_options[0] = quick_moves;
+	t_options[1] = animate_stagger;
+	t_options[2] = grid;
+	t_options[3] = flip_final;
+	t_options[4] = fast_cpu;	
+	t_tile_set = g_strdup (tile_set);
+	t_bg_color_name = g_strdup (bg_color_name);
 }
 
-static void 
-quick_moves_select (GtkWidget *widget, gpointer data)
+void
+apply_changes (void)
 {
-	if (GTK_TOGGLE_BUTTON (widget)->active)
-		t_quick_moves = 1;
-	else
-		t_quick_moves = 0;
-	apply_changes ();
+	if (bg_color_name)
+		g_free (bg_color_name);
+	if (tile_set)
+		g_free (tile_set);
+	black_computer_level = t_computer_level[0];
+	white_computer_level = t_computer_level[1];
+	animate = t_animate;
+	quick_moves     = t_options[0];
+	animate_stagger = t_options[1];
+	grid            = t_options[2];
+	flip_final      = t_options[3];
+	fast_cpu        = t_options[4];
+	tile_set = g_strdup (t_tile_set);
+	bg_color_name = g_strdup (t_bg_color_name);
+	computer_speed = COMPUTER_MOVE_DELAY;
+	flip_speed = PIXMAP_FLIP_DELAY;
+	if (quick_moves)
+	{
+		computer_speed /= 2;
+		flip_speed /= 2;
+	}
+	set_board_size ();
+	set_bg_color ();
+	load_pixmaps ();
+	set_flip_pixmaps_id ();
+	redraw_board ();
+	if (game_in_progress)
+		check_computer_players ();
 }
 
-static void 
-flip_final_select (GtkWidget *widget, gpointer data)
+static void
+on_computer_level_changed (GtkToggleButton *togglebutton, gpointer user_data)
 {
-	if (GTK_TOGGLE_BUTTON (widget)->active)
-		t_flip_final = 1;
-	else
-		t_flip_final = 0;
-	apply_changes ();	
+	if (!is_network_running () && togglebutton->active)
+		t_computer_level[GPOINTER_TO_INT (user_data) / 4] =
+				clamp_int (GPOINTER_TO_INT (user_data) % 4, 0, 3);
 }
 
 static void
-animate_stagger_select (GtkWidget *widget, gpointer data)
+on_animation_changed (GtkToggleButton *togglebutton, gpointer user_data)
 {
-	if (GTK_TOGGLE_BUTTON (widget)->active)
-		t_animate_stagger = 1;
-	else
-		t_animate_stagger = 0;
-	apply_changes ();	
+	if (togglebutton->active)
+		t_animate = clamp_int (GPOINTER_TO_INT (user_data), 0, 2);
 }
 
 static void
-grid_select (GtkWidget *widget, gpointer data)
+on_options_toggled (GtkToggleButton *togglebutton, gpointer user_data)
 {
-	if (GTK_TOGGLE_BUTTON (widget)->active)
-		t_grid = 1;
-	else
-		t_grid = 0;
-	apply_changes ();
+	t_options [GPOINTER_TO_INT (user_data)] = togglebutton->active;
 }
 
 static void
-animate_select (GtkWidget *widget, gpointer data)
+on_tile_set_box_changed (GtkComboBox *combobox, gpointer user_data)
 {
-	if (GTK_TOGGLE_BUTTON (widget)->active) {
-		t_animate = GPOINTER_TO_INT(data);
-	}
-	apply_changes ();	
+	if (t_tile_set)
+		g_free (t_tile_set);
+	t_tile_set = gtk_combo_box_get_active_text (combobox);
 }
 
 static void
-save_properties (void)
+on_color_button_color_set (GtkColorButton *colorbutton, gpointer user_data)
 {
-	GConfClient *client;
-
-	client = gconf_client_get_default ();
-
-	gconf_client_set_int (client, KEY_BLACK_LEVEL,
-			      black_computer_level, NULL);
-	gconf_client_set_int (client, KEY_WHITE_LEVEL,
-			      white_computer_level, NULL);
-
-	gconf_client_set_bool (client, KEY_QUICK_MOVES,
-			       t_quick_moves, NULL);
-
-	gconf_client_set_string (client, KEY_TILESET,
-				 tile_set_tmp, NULL);
-
-	gconf_client_set_int (client, KEY_ANIMATE,
-			      animate, NULL);
-
-	gconf_client_set_bool (client, KEY_ANIMATE_STAGGER,
-			       animate_stagger, NULL);
-	gconf_client_set_bool (client, KEY_SHOW_GRID,
-			       grid, NULL);
-	gconf_client_set_bool (client, KEY_FLIP_FINAL_RESULTS,
-			       flip_final, NULL);
+	gtk_color_button_get_color (colorbutton, &t_bg_color);
+	if (t_bg_color_name)
+		g_free (t_bg_color_name);
+	t_bg_color_name = g_strdup_printf ("#%04X%04X%04X",
+				t_bg_color.red, t_bg_color.green, t_bg_color.blue);
 }
 
 static void
-apply_changes (void)
+on_apply_button_clicked (GtkButton *button, gpointer user_data)
 {
-	guint i, j;
-	
-	black_computer_level = t_black_computer_level;
-	white_computer_level = t_white_computer_level;
-	
-	if (black_computer_id) {
-		g_source_remove (black_computer_id);
-		black_computer_id = 0;
-	}
-	
-	if (white_computer_id) {
-		g_source_remove (white_computer_id);
-		white_computer_id = 0;
-	}
-	
-	if (t_quick_moves)
-		computer_speed = COMPUTER_MOVE_DELAY / 2;
-	else
-		computer_speed = COMPUTER_MOVE_DELAY;
-	
-	if (strcmp (tile_set, tile_set_tmp)) {
-		g_free (tile_set);
-		tile_set = g_strdup (tile_set_tmp);
-		load_pixmaps ();
-		set_bg_color ();
-		for (i = 0; i < 8; i++)
-			for (j = 0; j < 8; j++)
-				if (pixmaps [i][j] >= BLACK_TURN &&
-						pixmaps[i][j] <= WHITE_TURN)
-					gui_draw_pixmap_buffer (pixmaps[i][j], i, j);
-				else
-					gui_draw_pixmap_buffer (0, i, j);
-		gui_draw_grid();
-	}
-	
-	animate = t_animate;
-	
-	if (flip_pixmaps_id) {
-		g_source_remove (flip_pixmaps_id);
-		flip_pixmaps_id = 0;
-	}
-	
-	switch (animate) {
-		case 0:
-			flip_pixmaps_id = g_timeout_add (100, flip_pixmaps,
-							   NULL);
-			break;
-		case 1:
-			flip_pixmaps_id = g_timeout_add (PIXMAP_FLIP_DELAY * 8,
-							 flip_pixmaps, NULL);
-			break;
-		case 2: flip_pixmaps_id = g_timeout_add (PIXMAP_FLIP_DELAY,
-							 flip_pixmaps, NULL);
-			break;
-	}
-	
-	animate_stagger = t_animate_stagger;
-
-	flip_final = t_flip_final;
-
-	if (grid != t_grid) {
-			grid = t_grid;
-			gui_draw_grid ();
-	}
-
-	check_computer_players ();
-
+	apply_changes ();
 	save_properties ();
 }
 
-static gboolean
-close_cb (GtkWidget *widget)
+static void
+on_properties_cancel_clicked (GtkButton *button, gpointer user_data)
 {
-	gtk_widget_hide (widget);
-
-	return TRUE;
+	reset_properties ();
+	gtk_widget_destroy (properties_dialog);
+	properties_dialog = NULL;
 }
 
-void
-set_selection (GtkWidget *widget, gpointer data)
+static void
+on_ok_button_clicked (GtkButton *button, gpointer user_data)
 {
-	gchar * filename;
-
-	if (tile_set_tmp)
-		g_free (tile_set_tmp);
-
-	filename = games_file_list_get_nth (theme_file_list,
-					    gtk_combo_box_get_active (GTK_COMBO_BOX (widget)));
-		
-	tile_set_tmp = g_strdup (filename);
-
 	apply_changes ();
+	save_properties ();
+	gtk_widget_destroy (properties_dialog);
+	properties_dialog = NULL;
 }
 
-void
-free_str (GtkWidget *widget, void *data)
-{
-        g_free(data);
-}
-
-static GtkWidget *
-fill_menu (void)
-{
-        gchar *dname = NULL;
-
-	/* FIXME: we need to check that both dname is valid and that
-	 * games_file_list_new_images returns something. */
-
-	dname = gnome_program_locate_file (NULL,
-					   GNOME_FILE_DOMAIN_APP_PIXMAP, 
-					   "iagno", FALSE, NULL);
-
-	if (theme_file_list)
-		g_object_unref (theme_file_list);
-
-	theme_file_list = games_file_list_new_images (dname, NULL);
-	g_free (dname);
-
-	games_file_list_transform_basename (theme_file_list);
-
-	return games_file_list_create_widget (theme_file_list, tile_set,
-					      GAMES_FILE_LIST_REMOVE_EXTENSION |
-					      GAMES_FILE_LIST_REPLACE_UNDERSCORES);
-}
-
-void
-show_properties_dialog (void)
+GtkWidget *
+create_properties_dialog (void)
 {
+	const gchar *strs [] = 
+	{
+		N_("Human"),            /* 0 */
+		N_("Level one"),        /* 1 */
+		N_("Level two"),        /* 2 */
+		N_("Level three"),      /* 3 */
+		N_("Dark"),             /* 4 */
+		N_("Light"),            /* 5 */
+		N_("None"),             /* 6 */
+		N_("Partial"),          /* 7 */
+		N_("Complete"),         /* 8 */
+		N_("_Use quick moves"), /* 9 */
+		N_("_Stagger flips"),   /* 10 */
+		N_("S_how grid"),       /* 11 */
+		N_("_Flip final results"), /* 12 */
+		N_("Fast _CPU"),        /* 13 */
+		N_("_Tile set:"),       /* 14 */
+		N_("BG color:"),        /* 15 */
+		N_("Animation"),        /* 16 */
+		N_("Options"),          /* 17 */
+		N_("Players"),          /* 18 */
+		N_("Appearance"),       /* 19 */
+		N_("Iagno Preferences"), /* 20 */
+		_("gtk-apply"),         /* 21 */
+		_("gtk-cancel"),        /* 22 */
+		_("gtk-ok")             /* 23 */
+	};
+	
+	const GtkSignalFunc *signalfunc[3] =
+	{
+		on_apply_button_clicked,
+		on_properties_cancel_clicked,
+		on_ok_button_clicked
+	};
+	
+	GtkWidget *properties_dialog;
+	GtkWidget *dialog_vbox;
 	GtkWidget *notebook;
-	GtkWidget *hbox;
+	GtkWidget *hbox1;
+	GtkWidget *frame;
+	GtkWidget *alignment;
+	GtkWidget *vbox2;
+	GtkWidget *button;
 	GtkWidget *label;
-	GtkWidget *label2;
+	GSList    *human_group[2] = {NULL, NULL};
+	GSList    *animation_group = NULL;
 	GtkWidget *table;
-	GtkWidget *button;
-	GtkWidget *frame;
-	GtkWidget *vbox, *vbox2;
-	GtkWidget *propbox = NULL;
-	GtkWidget *option_menu;
-
-	if (propbox) {
-                gtk_window_present (GTK_WINDOW (propbox));
-                return;
-	}
+	GtkWidget *tile_set_box;
+	GtkWidget *color_button;
+	GtkWidget *dialog_action_area;
+
+	gint n, f, v;
+	
+	properties_dialog = gtk_dialog_new ();
+	gtk_window_set_title (GTK_WINDOW (properties_dialog),strs[20]);
+	gtk_window_set_resizable (GTK_WINDOW (properties_dialog), FALSE);
+	gtk_window_set_type_hint (GTK_WINDOW (properties_dialog),
+				  GDK_WINDOW_TYPE_HINT_DIALOG);
 
-	reset_properties ();
+	dialog_vbox = GTK_DIALOG (properties_dialog)->vbox;
 
-	propbox = gtk_dialog_new_with_buttons (_("Iagno Preferences"),
-			GTK_WINDOW (window),
-			0,
-			GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
-        
-        gtk_dialog_set_has_separator (GTK_DIALOG (propbox), FALSE);
-	gtk_container_set_border_width (GTK_CONTAINER (propbox), 5);
-	gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (propbox)->vbox), 2);
-	gtk_window_set_resizable (GTK_WINDOW (propbox), FALSE);
 	notebook = gtk_notebook_new ();
-	gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
-	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (propbox)->vbox),
-                           notebook);
-
-	label = gtk_label_new (_("Players"));
-
-	vbox = gtk_vbox_new (FALSE, 18);
-	gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
-	gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
-                                  vbox, label);
-        
-        table = gtk_table_new (1, 2, FALSE);
-	gtk_table_set_col_spacings (GTK_TABLE (table), 18);
-        gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
-
-	vbox2 = gtk_vbox_new (FALSE, 0);
-        gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
-
-	button = gtk_check_button_new_with_mnemonic (_("_Use quick moves"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-                                      (computer_speed == COMPUTER_MOVE_DELAY / 2));
-	g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK
-                          (quick_moves_select), NULL);
-	
-	gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
-        
-
-	frame = games_frame_new (_("Dark"));
-        gtk_table_attach_defaults (GTK_TABLE (table), frame, 0, 1, 0, 1);
-
-	vbox = gtk_vbox_new (FALSE, 6);
-
-	button = gtk_radio_button_new_with_label (NULL, _("Human"));
-	if (black_computer_level == 0)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (black_computer_level_select),
-			(gpointer) 0);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	button = gtk_radio_button_new_with_label (gtk_radio_button_get_group
-			(GTK_RADIO_BUTTON (button)), _("Level one"));
-	if (black_computer_level == 1)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (black_computer_level_select),
-			(gpointer) 1);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	button = gtk_radio_button_new_with_label (gtk_radio_button_get_group
-			(GTK_RADIO_BUTTON (button)), _("Level two"));
-	if (black_computer_level == 2)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (black_computer_level_select),
-			(gpointer) 2);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	button = gtk_radio_button_new_with_label (gtk_radio_button_get_group
-			(GTK_RADIO_BUTTON (button)), _("Level three"));
-	if (black_computer_level == 3)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (black_computer_level_select),
-			(gpointer) 3);
+	gtk_box_pack_start (GTK_BOX (dialog_vbox), notebook, TRUE, TRUE, 0);
 
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	gtk_container_add (GTK_CONTAINER (frame), vbox);
-
-	frame = games_frame_new (_("Light"));
-        gtk_table_attach_defaults (GTK_TABLE (table), frame, 1, 2, 0, 1);
-	
-	vbox = gtk_vbox_new (FALSE, 6);
-	
-	button = gtk_radio_button_new_with_label (NULL, _("Human"));
-	if (white_computer_level == 0)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (white_computer_level_select),
-			(gpointer) 0);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	button = gtk_radio_button_new_with_label (gtk_radio_button_get_group
-			(GTK_RADIO_BUTTON (button)), _("Level one"));
-	if (white_computer_level == 1)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-                          G_CALLBACK (white_computer_level_select),
-                          (gpointer) 1);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	button = gtk_radio_button_new_with_label (gtk_radio_button_get_group
-			(GTK_RADIO_BUTTON (button)), _("Level two"));
-	if (white_computer_level == 2)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-                          G_CALLBACK (white_computer_level_select),
-                          (gpointer) 2);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	button = gtk_radio_button_new_with_label (gtk_radio_button_get_group
-                                                  (GTK_RADIO_BUTTON (button)),
-                                                  _("Level three"));
-	if (white_computer_level == 3)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (white_computer_level_select),
-			(gpointer) 3);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	
-	gtk_container_add (GTK_CONTAINER (frame), vbox);
+	for (n = 0; n < 2; n++)
+	{
+		hbox1 = gtk_hbox_new (FALSE, 0);
+		gtk_container_add (GTK_CONTAINER (notebook), hbox1);
+
+		if ( n == 0)
+		{
+			for (f = 0; f < 2; f++)
+			{
+				frame = gtk_frame_new (NULL);
+				gtk_box_pack_start (GTK_BOX (hbox1), frame, TRUE, TRUE, 0);
+				gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
+
+				alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
+				gtk_container_add (GTK_CONTAINER (frame), alignment);
+				gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
+
+				vbox2 = gtk_vbox_new (FALSE, 0);
+				gtk_container_add (GTK_CONTAINER (alignment), vbox2);
+
+				for (v = 0; v < 4; v++)
+				{
+					button = gtk_radio_button_new_with_mnemonic (NULL, strs[v]);
+					gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
+					gtk_radio_button_set_group (GTK_RADIO_BUTTON (button), human_group[f]);
+					human_group[f] = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
+					gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+							(t_computer_level[f] == v));
+					g_signal_connect ((gpointer) button, "toggled",
+							G_CALLBACK (on_computer_level_changed), GINT_TO_POINTER (f*4+v));
+				}
+
+				label = gtk_label_new (strs[f+4]);
+				gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+				gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+			}
+		}
+		else
+		{
+			for (f = 0; f < 2; f++)
+			{
+				frame = gtk_frame_new (NULL);
+				gtk_box_pack_start (GTK_BOX (hbox1), frame, TRUE, TRUE, 0);
+				gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
+
+				alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
+				gtk_container_add (GTK_CONTAINER (frame), alignment);
+				gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
+
+				vbox2 = gtk_vbox_new (FALSE, 0);
+				gtk_container_add (GTK_CONTAINER (alignment), vbox2);
+				if (f == 0)
+				{
+					for (v = 0; v < 3; v++)
+					{
+						button = gtk_radio_button_new_with_mnemonic (NULL, strs[v+6]);
+						gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
+						gtk_radio_button_set_group (GTK_RADIO_BUTTON (button), animation_group);
+						animation_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
+						gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), (t_animate == v));
+						g_signal_connect ((gpointer) button, "toggled",
+							G_CALLBACK (on_animation_changed), GINT_TO_POINTER (v));
+					}
+				}	
+				else
+				{
+					for (v = 0; v < 5; v++)
+					{
+						button = gtk_check_button_new_with_mnemonic (strs[v+9]);
+						gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
+						gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), t_options[v]);
+						g_signal_connect ((gpointer) button, "toggled",
+							G_CALLBACK (on_options_toggled), GINT_TO_POINTER (v));
+					}
+
+					table = gtk_table_new (2, 2, FALSE);
+					gtk_box_pack_start (GTK_BOX (vbox2), table, FALSE, FALSE, 0);
+
+					for (v = 0; v < 2; v++)
+					{
+						label = gtk_label_new (strs[v+14]);
+						gtk_table_attach (GTK_TABLE (table), label, 0, 1, v, v+1,
+							(GtkAttachOptions) (0),
+							(GtkAttachOptions) (0), 0, 0);
+						gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+					}
+			
+					tile_set_box = gtk_combo_box_new_text ();
+					gtk_table_attach (GTK_TABLE (table), tile_set_box, 1, 2, 0, 1,
+						(GtkAttachOptions) (0),
+						(GtkAttachOptions) (0), 0, 0);
+					gtk_combo_box_append_text (GTK_COMBO_BOX (tile_set_box), _("classic.png"));
+					gtk_combo_box_append_text (GTK_COMBO_BOX (tile_set_box), _("woodtrim.png"));
+					if (g_str_equal (t_tile_set, _("woodtrim.png")))
+						gtk_combo_box_set_active (GTK_COMBO_BOX (tile_set_box), 1);
+					else
+						gtk_combo_box_set_active (GTK_COMBO_BOX (tile_set_box), 0);
+					g_signal_connect ((gpointer) tile_set_box, "changed",
+						G_CALLBACK (on_tile_set_box_changed), NULL);
+
+					color_button = gtk_color_button_new ();
+					gtk_table_attach (GTK_TABLE (table), color_button, 1, 2, 1, 2,
+						(GtkAttachOptions) (0),
+						(GtkAttachOptions) (0), 0, 0);
+					gtk_color_button_set_color ((GtkColorButton *) color_button, &t_bg_color);
+					g_signal_connect ((gpointer) color_button, "color_set",
+						G_CALLBACK (on_color_button_color_set), NULL);
+				}
+
+				label = gtk_label_new (strs[f + 16]);
+				gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+				gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+			}
+		}
+		label = gtk_label_new (strs[n+18]);
+		gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook),
+		gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), n),label);
+	}
+
+	dialog_action_area = GTK_DIALOG (properties_dialog)->action_area;
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area),
+				GTK_BUTTONBOX_END);
+
+	for (v = 0; v < 3; v ++)
+	{
+		button = gtk_button_new_from_stock (strs[v+21]);
+		gtk_dialog_add_action_widget (GTK_DIALOG (properties_dialog),
+				      	button, GTK_RESPONSE_APPLY);
+		GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+		g_signal_connect ((gpointer) button, "clicked",
+					G_CALLBACK (signalfunc[v]), NULL);
+	};
 
+	gtk_widget_show_all (properties_dialog);
+	return properties_dialog;
+}
 
-        label = gtk_label_new (_("Appearance"));
+static void
+write_kifu (int fd)
+{
+	gchar buf[9];
+	gint8 i;
+	ssize_t err;
+
+	i = 0;
+	buf[2] = buf[4] = 0x20;
+	buf[7] = 0x0A;
+	buf[8] = 0;
+
+	err = write (fd, _("iagno\n"), 6);
+	while (kifu[i][0] && err > 0)
+	{
+		buf[0] = (i + 1) / 10 + 0x30;
+		buf[1] = (i + 1) % 10 + 0x30;
+		buf[3] = (kifu[i][0] == BLACK_TURN) ? 0x42 : 0x57;
+		buf[5] = kifu[i][1] % 10 + 0x40;
+		buf[6] = kifu[i][1] / 10 + 0x30;
 
-	table = gtk_table_new (1, 2, FALSE);
-	gtk_table_set_col_spacings (GTK_TABLE (table), 18);
-	gtk_container_set_border_width (GTK_CONTAINER (table), 12);
-	
-	frame = games_frame_new (_("Animation"));
-	
-	vbox = gtk_vbox_new (FALSE, 6);
-	
-	button = gtk_radio_button_new_with_label (NULL, _("None"));
-	if (animate == 0)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (animate_select), (gpointer) 0);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	button = gtk_radio_button_new_with_label (gtk_radio_button_get_group
-			(GTK_RADIO_BUTTON (button)), _("Partial"));
-	if (animate == 1)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (animate_select), (gpointer) 1);
-
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	button = gtk_radio_button_new_with_label (gtk_radio_button_get_group
-			(GTK_RADIO_BUTTON (button)), _("Complete"));
-	if (animate == 2)
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-				TRUE);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (animate_select), (gpointer) 2);
+		err = write (fd, buf, 8);
+		i++;
+	}
+}
 
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	
-	gtk_container_add (GTK_CONTAINER (frame), vbox);
-	gtk_table_attach_defaults (GTK_TABLE (table), frame, 0, 1, 0, 1);
-	
-        frame = games_frame_new (_("Options"));
-	vbox = gtk_vbox_new (FALSE, 6);
-	gtk_container_add (GTK_CONTAINER (frame), vbox);
-	button = gtk_check_button_new_with_mnemonic (_("_Stagger flips"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-			t_animate_stagger);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (animate_stagger_select), NULL);
-	
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+static void
+read_kifu (int fd)
+{
+	gchar buf[9];
+	gint8 i = 0;
+	ssize_t err;
+
+	err = read (fd, buf, 6);
+	buf[6] = 0;
+	if (!g_str_equal (buf, _("iagno\n")))
+	{
+		gui_message (_("not iagno's file"));
+		return;
+	}
+	err = read (fd, buf, 8);
+	while (err > 0)
+	{
+		i = (buf[0] - 0x30) * 10 + buf[1] - 0x30 - 1;
+		kifu[i][0] = (buf[3] == 0x42) ? BLACK_TURN : WHITE_TURN;
+		kifu[i][1] = (buf[6] - 0x30) * 10 + buf[5] - 0x40;
+		err = read (fd, buf, 8);
+	}
+	kifu[i + 1][0] = 0;
+}
 
-	button = gtk_check_button_new_with_mnemonic (_("S_how grid"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-			t_grid);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (grid_select), NULL);
-	
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+static void
+on_save_clicked (GtkButton *button, gpointer user_data)
+{
+	gchar *filename;
+	int fd;
 
-	button = gtk_check_button_new_with_mnemonic (_("_Flip final results"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-			t_flip_final);
-	g_signal_connect (G_OBJECT (button), "toggled",
-			G_CALLBACK (flip_final_select), NULL);
+	filename =
+		gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_save_dialog));
 
-	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-	
-	hbox = gtk_hbox_new (FALSE, 12);
-	
-	label2 = gtk_label_new_with_mnemonic (_("_Tile set:"));
-	
-	gtk_box_pack_start (GTK_BOX (hbox), label2, FALSE, FALSE, 0);
-	
-	option_menu = fill_menu ();
-	gtk_label_set_mnemonic_widget (GTK_LABEL (label2), option_menu);
-	g_signal_connect(G_OBJECT(option_menu), "changed",
-			 G_CALLBACK (set_selection), NULL);
-	gtk_box_pack_start (GTK_BOX (hbox), option_menu, TRUE, TRUE, 0);
-	
-	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-	
-	gtk_table_attach_defaults (GTK_TABLE (table), frame, 1, 2, 0, 1);
+	fd = creat (filename, 0644);
+	if (fd)
+	{
+		write_kifu (fd);
+		close (fd);
+	}
+	gtk_widget_destroy (file_save_dialog);
+	g_free (filename);
+}
 
-	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), table,
-                                  label);
-        
-	g_signal_connect (G_OBJECT (propbox), "response", G_CALLBACK
-			(close_cb), NULL);
-	g_signal_connect (G_OBJECT (propbox), "delete_event", G_CALLBACK
-			(close_cb), NULL);
+static void
+on_open_clicked (GtkButton *button, gpointer user_data)
+{
+	gchar *filename;
+	int fd;
 
-	gtk_widget_show_all (propbox);
+	filename =
+		gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_open_dialog));
+	fd = open (filename, 0, 0644);
+	if (fd)
+	{
+		read_kifu (fd);
+		close (fd);
+	}
+	gtk_widget_destroy (file_open_dialog);
+	g_free (filename);
+	on_head_button_clicked (NULL, NULL);
+}
+
+GtkWidget *
+create_file_save_dialog (void)
+{
+	GtkWidget *file_save_dialog;
+	GtkWidget *dialog_vbox;
+	GtkWidget *dialog_action_area;
+	GtkWidget *save_cancel;
+	GtkWidget *save;
+
+	file_save_dialog =
+		gtk_file_chooser_dialog_new ("", NULL,
+					GTK_FILE_CHOOSER_ACTION_SAVE, NULL);
+	gtk_window_set_type_hint (GTK_WINDOW (file_save_dialog),
+				GDK_WINDOW_TYPE_HINT_DIALOG);
+	g_signal_connect ((gpointer) file_save_dialog, "destroy",
+				G_CALLBACK (gtk_widget_destroy), NULL);
+
+	dialog_vbox = GTK_DIALOG (file_save_dialog)->vbox;
+
+	dialog_action_area = GTK_DIALOG (file_save_dialog)->action_area;
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area),
+				GTK_BUTTONBOX_END);
+
+	save_cancel = gtk_button_new_from_stock ("gtk-cancel");
+	gtk_dialog_add_action_widget (GTK_DIALOG (file_save_dialog),
+				save_cancel, GTK_RESPONSE_CANCEL);
+	GTK_WIDGET_SET_FLAGS (save_cancel, GTK_CAN_DEFAULT);
+	g_signal_connect_swapped ((gpointer) save_cancel, "clicked",
+				G_CALLBACK (gtk_widget_destroy), (gpointer) file_save_dialog);
+
+	save = gtk_button_new_from_stock ("gtk-save");
+	gtk_dialog_add_action_widget (GTK_DIALOG (file_save_dialog), save,
+				GTK_RESPONSE_OK);
+	GTK_WIDGET_SET_FLAGS (save, GTK_CAN_DEFAULT);
+	g_signal_connect ((gpointer) save, "clicked",
+				G_CALLBACK (on_save_clicked), NULL);
+
+	gtk_widget_show_all (file_save_dialog);
+	gtk_widget_grab_default (save);
+	return file_save_dialog;
+}
+
+GtkWidget *
+create_file_open_dialog (void)
+{
+	GtkWidget *file_open_dialog;
+	GtkWidget *dialog_vbox;
+	GtkWidget *dialog_action_area;
+	GtkWidget *open_cancel;
+	GtkWidget *open;
+
+	file_open_dialog =
+		gtk_file_chooser_dialog_new ("", NULL,
+					     GTK_FILE_CHOOSER_ACTION_OPEN, NULL);
+	gtk_window_set_type_hint (GTK_WINDOW (file_open_dialog),
+				  GDK_WINDOW_TYPE_HINT_DIALOG);
+	g_signal_connect ((gpointer) file_open_dialog, "destroy",
+			  G_CALLBACK (gtk_widget_destroy), NULL);
+
+	dialog_vbox = GTK_DIALOG (file_open_dialog)->vbox;
+
+	dialog_action_area = GTK_DIALOG (file_open_dialog)->action_area;
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area),
+				   GTK_BUTTONBOX_END);
+
+	open_cancel = gtk_button_new_from_stock ("gtk-cancel");
+	gtk_dialog_add_action_widget (GTK_DIALOG (file_open_dialog),
+				      open_cancel, GTK_RESPONSE_CANCEL);
+	GTK_WIDGET_SET_FLAGS (open_cancel, GTK_CAN_DEFAULT);
+	g_signal_connect_swapped ((gpointer) open_cancel, "clicked",
+			  G_CALLBACK (gtk_widget_destroy), (gpointer) file_open_dialog);
+
+	open = gtk_button_new_from_stock ("gtk-open");
+	gtk_dialog_add_action_widget (GTK_DIALOG (file_open_dialog), open,
+				      GTK_RESPONSE_OK);
+	GTK_WIDGET_SET_FLAGS (open, GTK_CAN_DEFAULT);
+	g_signal_connect ((gpointer) open, "clicked",
+			  G_CALLBACK (on_open_clicked), NULL);
+
+	gtk_widget_show_all (file_open_dialog);
+	gtk_widget_grab_default (open);
+	return file_open_dialog;
 }
Index: gnome-games/iagno/properties.h
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/properties.h,v
retrieving revision 1.2
diff -u -r1.2 properties.h
--- gnome-games/iagno/properties.h	18 Jun 2003 15:54:41 -0000	1.2
+++ gnome-games/iagno/properties.h	23 Aug 2006 22:07:59 -0000
@@ -1,7 +1,38 @@
+/*
+ * properties.h
+ *
+ * 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
+ *
+ * For more details see the file COPYING.
+ */
+
 #ifndef _PROPERTIES_H_
 #define _PROPERTIES_H_
 
 void load_properties (void);
-void show_properties_dialog (void);
+
+void save_properties (void);
+
+void reset_properties (void);
+
+void apply_changes (void);
+
+GtkWidget* create_properties_dialog (void);
+
+GtkWidget* create_file_save_dialog (void);
+
+GtkWidget* create_file_open_dialog (void);
 
 #endif
Index: gnome-games/iagno/woodtrim.png
===================================================================
RCS file: /cvs/gnome/gnome-games/iagno/woodtrim.png,v
retrieving revision 1.1
diff -u -r1.1 woodtrim.png
Binary files /tmp/cvs95kuJL and woodtrim.png differ
