Plan 9 from Bell Labs’s /usr/web/sources/contrib/paurea/goban/tryrules.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <draw.h>
#include <thread.h>
#include <igo.h>

extern char goban[Bansz+1][Bansz+1];
int verbose;
int      mainstacksize = Stacksz;

char *argv0;

void
usage(void)
{
	fprint(2, "usage: %s [-v]\n", argv0);
	sysfatal("usage: %s [-v]\n", argv0);
}

void
threadmain(int argc, char **argv)
{
	Move *m, *grp;
	int nw, nb;
	int ndead;

	ARGBEGIN{
	case 'v';
		verbose ++
		break;
	} ARGEND

	if(argc)
		usage();

	fmtinstall('P', Pfmt);
	cleangoban();
	goban[1][1] = Bstone;
	goban[2][1] = Bstone;
	m = getmove(Pt(1, 1));
	grp = getgrp(m, nil);
dprint("Contiguous, should be 1,1 2,1\n");
	opgrp(grp, '\0', opprint);
	freegrp(grp);
	free(m);

	m = getmove(Pt(1, 1));
	grp = getgrp(m, "e");
dprint("Empty, should be 3,1 2,2 1,2\n");
	opgrp(grp, '\0', opprint);
	freegrp(grp);
	free(m);

	goban[1][2] = Wstone;
	m = getmove(Pt(1, 1));
	grp = getgrp(m, "eW");
dprint("Empty, should be 3,1 2,2, White is 1,2\n");
	opgrp(grp, '\0', opprint);
	freegrp(grp);
	free(m);

	grp = nil;
	m = getmove(Pt(3, 1));
	m->type = Wstone;
	ndead = move(m, &grp);
dprint("Number of deads 3,1 should be none: %d\n", ndead);
	opgrp(grp, '\0', opprint);
	free(m);
	freegrp(grp);

	grp = nil;
	m = getmove(Pt(2, 2));
	m->type = Wstone;
	ndead = move(m, &grp);
dprint("Number of deads 2,2 should be two: %d\n", ndead);
	opgrp(grp, '\0', opprint);
	free(m);
	freegrp(grp);
dprint("Count\n");
	goban[8][8] = Bstone;
	trycount(&nw, &nb);
dprint("Goban 1 1 %c\n", goban[1][1]);
dprint("Counted w:%d, b:%d, should be white two\n", nw, nb);
	
	cleangoban();
	goban[1][2] = Wstone;
	goban[2][1] = Wstone;	
	goban[3][3] = Bstone;
	trycount(&nw, &nb);
dprint("Counted w:%d, b:%d, should be white one\n", nw, nb);

	cleangoban();
	goban[1][2] = Wstone;
	goban[2][1] = Wstone;	
	goban[1][1] = Bstone;
	trycount(&nw, &nb);
dprint("Counted w:%d, b:%d, should be white 358\n", nw, nb);
	sleep(2);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.