wm: glendy

ref: c92eb2ffeaf2011ec73c7ad66b317484f80eb446
dir: /doc/glendy2.man/

View raw version
.TH GLENDY 2
.SH NAME
initlevel, pointdir, movedir, domove,
doput, findglenda, checknext, score1, clac, nextglenda,
restart, undo, checkstate \- libglendy functions
.SH SYNOPSIS
.EX
.sp 0.3v
#include "engine.h"

enum
{
	/* difficulty levels (walls on the map) */
	DEasy,	/* 10≤x<15 */
	DMed,	/* 5≤x<10 */
	DHard,	/* 1≤x<5 */
	DImp, /* 0 */

	/* map size */
	SzX = 11,
	SzY = 11, 

	/* movement directions */
	NE,
	E,
	SE,
	SW,
	W,
	NW,

	/* player types */
	Human = 0,
	Computer,
	Net,

	/* state of a game */
	Init = 0,
	Start,
	Playing,
	Won,	
	Lost,

	/* elements on the map */
	Prev = 100, /* glenda's previous location */
	Wall = 999,
	Glenda = 1000,

	Err = 0,
	Ok,
};

void initlevel(void);
Point movedir(int dir, Point p);
int pointdir(Point src, Point dst);

int domove(int dir);
int doput(Point p);

Point findglenda(void);
int checknext(int dir, Point p);

int score1(Point p);
void calc(void);
void nextglenda(void);

int findmin(void);
int checkstate(void);

void restart(void);
void undo(void);

.SH DESCRIPTION
These library provides functions to deal with
.I glendy
game logic and make writing clients and servers easier.

.I initlevel
sets up the map with glenda always on middle
and amount of walls based on 
.I difficulity
variable,
.TP 10
.B DEasy
10 ≤ x ≤ 15
.TP 10
.B DMed
5 ≤ x ≤ 10
.TP 10
.B Dhard
1 ≤ x ≤ 5
.TP 10
.B DImp
x = 0
.PP
where 
.B x
is amount of walls, chosen randomly.

.PP
.I movedir
function returns the point
.I p
after being moved in
.I dir
direction,
or
.B {-1, -1}
in case of invalid input.
.I pointdir
is the reverse of
.I movedir
function, returning what direction
.I src
needs to be moved to reach
.I dst
or
.B Err
if it can't be reached in one move.

.I domove
and
.I doput
are used by clients to handle actions for glenda
and trapper (the player who puts the walls).
they
returns
.B Wall
and
.B Glenda
if the cell is not empty.
.PP
.I findglenda
returns first cell which has
.B Glenda
inside.
.I checknext
is a depracated varient of
.I pointdir.
.PP
.I score1 ,
.I calc
and
.I nextglenda
Score1 calculates how many turns would it take to reach the edge from a specifc point in grid.
Calc sets the score of whole map, and nextglenda makes a move based on shortest path.
if there are two (or more) equally short paths, it will pick one randomly.
.PP
.I restart
reverts grid layout to
.B ogrid 
and sets turn to 0.
.I undo 
undos to last move done by tapper, sets
to
.B turn - 2.
it's expected to be buggy, and only works once.
(further calls to
.I undo
reverts the map to orignal state before first call of undo.)