1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
* makebearoff.c
*
* by Gary Wong <gary@cs.arizona.edu>, 1997-1999.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 3 or later of the GNU General Public License as
* published by the Free Software Foundation.
*
* 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
*
* $Id: bearoffdump.c,v 1.16 2008/03/18 22:51:34 c_anthon Exp $
*/
#include "config.h"
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "positionid.h"
#include "bearoff.h"
#include "multithread.h"
#include "backgammon.h"
#if USE_MULTITHREAD
extern int MT_GetThreadID(void)
{
return (0);
}
extern void MT_Release(void)
{
return;
}
extern void MT_Exclusive(void)
{
return;
}
#else
extern void CallbackProgress(void)
{
}
#endif
extern int
main( int argc, char **argv ) {
char *filename, *szPosID = NULL;
int id = 0;
bearoffcontext *pbc;
char sz[ 4096 ];
int n;
int nUs;
int nThem;
TanBoard anBoard;
GOptionEntry ao[] = {
{"index", 'n', 0, G_OPTION_ARG_INT, &id,
"index", NULL},
{"posid", 'p', 0, G_OPTION_ARG_STRING, &szPosID,
"Position ID", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
GError *error = NULL;
GOptionContext *context;
context = g_option_context_new("file");
g_option_context_add_main_entries(context, ao, PACKAGE);
g_option_context_parse(context, &argc, &argv, &error);
g_option_context_free(context);
if (error) {
g_printerr("%s\n", error->message);
exit(EXIT_FAILURE);
}
if ((szPosID && id) || (!szPosID && !id))
{
g_printerr("Either Position ID or index is required. Not Both.\n"
"For more help try `bearoffdump --help'\n");
exit(EXIT_FAILURE);
}
if (argc != 2)
{
g_printerr("A bearoff database file should be given as an"
"argument\nFor more help try `bearoffdump --help'\n");
exit(EXIT_FAILURE);
}
filename = argv[ 1 ];
printf( "Bearoff database: %s\n", filename );
if ( !id ) {
printf( "Position ID : %s\n", szPosID );
}
else {
printf( "Position number : %d\n", id );
}
if ( ! ( pbc = BearoffInit ( filename, BO_NONE, NULL ) ) ) {
printf( "Failed to initialise bearoff database %s\n", filename );
exit(-1);
}
/* information about bearoff database */
printf( "\n"
"Information about database:\n\n" );
*sz = 0;
BearoffStatus( pbc, sz );
puts( sz );
/* set up board */
memset( anBoard, 0, sizeof anBoard );
if ( !id ) {
printf( "\n"
"Dump of position ID: %s\n\n", szPosID );
PositionFromID( anBoard, szPosID );
}
else {
printf( "\n"
"Dump of position#: %d\n\n", id );
n = Combination ( pbc->nPoints + pbc->nChequers, pbc->nPoints );
nUs = id / n;
nThem = id % n;
PositionFromBearoff( anBoard[ 0 ], nThem, pbc->nPoints, pbc->nChequers );
PositionFromBearoff( anBoard[ 1 ], nUs, pbc->nPoints, pbc->nChequers );
}
/* dump req. position */
*sz = 0;
BearoffDump( pbc, (ConstTanBoard)anBoard, sz );
puts( sz );
BearoffClose( pbc );
return 0;
}
|