⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 human.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic	char sccsid[] = "@(#)human.c 1.1 92/07/30 Copyr 1985 Sun Micro";#endif/* * Copyright (c) 1985 by Sun Microsystems, Inc. */#include <sys/time.h>#include <sys/types.h>#include <sunwindow/win_input.h>#include "defs.h"#define INTERMED	8int humanmoves[4][4];int intpnts[3][2], intcntr;	/* intermediate points in a move */int rollstack[4], rollcntr;	/* rolls used in a move */int humannomove;		/* human couldn't move on last turn */gammon_reader(ie)struct inputevent *ie;{	static int movingpiece = 0, from, to, oldx = -1, oldy = -1;	if (state != MOVE && ie->ie_code == LOC_WINEXIT)		return;	if (state != MOVE && ie->ie_code == LOC_MOVEWHILEBUTDOWN)		return;	if (win_inputposevent(ie)) {		if (ie->ie_code != LOC_MOVEWHILEBUTDOWN)			message(ERR, "");		switch (state) {		case STARTGAME:			if (ie->ie_code == MS_LEFT || ie->ie_code == MS_MIDDLE)				initgame();			break;		case ROLL:			if (ie->ie_code == MS_LEFT || ie->ie_code == MS_MIDDLE) {				rolldice(HUMAN);				message(MSG, "Your turn to move.");				starthumanturn();			}			break;		case MOVE:			if (ie->ie_code == MS_LEFT || ie->ie_code == MS_MIDDLE) {				from = getpoint(ie->ie_locx, ie->ie_locy);				if (legalstart(from))					movingpiece = 1;			} else if (ie->ie_code == LOC_MOVEWHILEBUTDOWN) {				if (!movingpiece)					break;				if (oldx >= 0 && oldy >= 0)					drawoutline(oldx, oldy);				oldx = ie->ie_locx;				oldy = ie->ie_locy;				drawoutline(oldx, oldy);				break;			} else if (ie->ie_code == LOC_WINEXIT) {				if (!movingpiece)					break;				movingpiece = 0;				if (oldx >= 0 && oldy >= 0) {					drawoutline(oldx, oldy);					oldx = oldy = -1;				}			}			break;		case THINKING:			message(ERR, "It's not your turn!");			break;		case GAMEOVER:			message(ERR, "The game is over!");			break;		case COMPUTERDOUBLING:			message(ERR, "You must accept or refuse the computer's double!");			break;		case HUMANDOUBLING:			message(ERR, "Hold on, the computer is thinking about whether to accept your double!");			break;		} /* end switch */	} else {	/* this is a negative event */		if ((ie->ie_code == MS_LEFT || ie->ie_code == MS_MIDDLE) && movingpiece) {			to = getpoint(ie->ie_locx, ie->ie_locy);			if (oldx >= 0 || oldy >= 0) {				drawoutline(oldx, oldy);				oldx = oldy = -1;			}			movingpiece = 0;			if (legalend(to))				if (legalmove(from, to))					domove(from, to);		}	}}legalstart(point)int point;{	if (point == OUTOFBOUNDS || point == HOME)		return(0);	if (humanboard[point] == 0)		return(0);	if (point != BAR && humanboard[BAR] != 0) {		message(ERR, "You must remove your barmen!");		return(0);	}	return(1);}legalend(point)int point;{	if (point == OUTOFBOUNDS || point == BAR)		return(0);	if (computerboard[point] > 1 && point != HOME) {		message(ERR, "You cannot land on a blocked point!");		return(0);	}	return(1);}legalmove(from, to)int from, to;{	int rollneeded, dice[2], numdice, index, furthest, midpnt;	if (to == HOME) {		for (index = 24; index > 6; index--) {			if (index == from && humanboard[index] == 1)				continue;			if (humanboard[index] > 0) {				message(ERR, "You cannot bear off until all your pieces are in your inner table!");				return(0);			}		}	}	clearintermediatepnts();	if (from == to)		return(0);	if (from == BAR && to == HOME)	/* never possible, and it messes */		return(0);		/* up the algorithm */	if (from == BAR)		rollneeded = 25 - to;	else if (to == HOME)		rollneeded = from;	else		rollneeded = from - to;	if (rollneeded < 0) {		message(ERR, "Backwards move!");		return(0);	}        if (humanboard[BAR] > 1 && rollneeded == humandieroll[0] + humandieroll[1]) {                message(ERR, "You must remove all of your barmen!");                return(0);	}	if (to == HOME) {		for (furthest = 6; furthest > 1; furthest--) {			if (humanboard[furthest] > 0)				break;		}	}	if ((humandieroll[0] & NUMMASK) == (humandieroll[1] & NUMMASK)) {		if ((humandieroll[0] & ROLLUSED) == 0)			numdice = 4;		else if ((humandieroll[0] & SECONDROLLUSED) == 0)			numdice = 3;		else if ((humandieroll[1] & ROLLUSED) == 0)			numdice = 2;		else			numdice = 1;		if (rollneeded % (humandieroll[0] & NUMMASK) == 0) {			if (rollneeded / (humandieroll[0] & NUMMASK) > numdice) {				message(ERR, "You didn't roll that move!");				return(0);			}			midpnt = from;			for (index = 0; index < numdice; index++) {				if ((rollneeded -= (humandieroll[0] & NUMMASK)) <= 0) {					useroll(humandieroll[0] & NUMMASK);					break;				}				midpnt -= humandieroll[0] & NUMMASK;				if (computerboard[midpnt] == 1) {					addintermediatepnt(midpnt, 1);				} else if (computerboard[midpnt] <= 0) {					addintermediatepnt(midpnt, 0);				} else {					message(ERR, "You cannot touch down on a blocked point!");					return(0);				}				useroll(humandieroll[0] & NUMMASK);			}			return(1);		} else if (to == HOME) {			if (numdice * (humandieroll[0] & NUMMASK) < rollneeded) {				message(ERR, "You didn't roll that move!");				return(0);			}			if (from != furthest) {				message(ERR, "You didn't roll that move!");				return(0);			}			midpnt = from;			for (index = 0; index < numdice; index++) {				if ((rollneeded -= (humandieroll[0] & NUMMASK)) <= 0) {					useroll(humandieroll[0] & NUMMASK);					break;				}				midpnt -= humandieroll[0] & NUMMASK;				for (furthest = 6; furthest > 1; furthest--) {					if (humanboard[furthest] > 0 && !(furthest == from && humanboard[from] == 1))						break;				}				if (midpnt != furthest) {					message(ERR, "You didn't roll that move!");					return(0);				}				if (computerboard[midpnt] == 1) {					addintermediatepnt(midpnt, 1);				} else if (computerboard[midpnt] <= 0) {					addintermediatepnt(midpnt, 0);				} else {					message(ERR, "You cannot touch down on a blocked point!");					return(0);				}				useroll(humandieroll[0] & NUMMASK);			}			return(1);		} else {			message(ERR, "You didn't roll that move!");			return(0);		}	} else {	/* not doubles */		if (humandieroll[0] & ROLLUSED) {			dice[0] = humandieroll[1] & NUMMASK;			numdice = 1;		} else if (humandieroll[1] & ROLLUSED) {			dice[0] = humandieroll[0] & NUMMASK;			numdice = 1;		} else {			dice[0] = humandieroll[0] & NUMMASK;			dice[1] = humandieroll[1] & NUMMASK;			numdice = 2;		}		if (rollneeded == dice[0]) {			useroll(dice[0]);			return(1);		}		if (numdice == 2 && rollneeded == dice[1]) {			useroll(dice[1]);			return(1);		}		if (numdice == 2 && rollneeded == dice[0] + dice[1]) {			midpnt = from - (humandieroll[0] & NUMMASK);			if (computerboard[midpnt] == 1) {				useroll(dice[0]);				useroll(dice[1]);				addintermediatepnt(midpnt, 1);				return(1);			}			if (computerboard[midpnt] <= 0) {				useroll(dice[0]);				useroll(dice[1]);				addintermediatepnt(midpnt, 0);				return(1);			}			midpnt = from - (humandieroll[1] & NUMMASK);			if (computerboard[midpnt] == 1) {				useroll(dice[0]);				useroll(dice[1]);				addintermediatepnt(midpnt, 1);				return(1);			}			if (computerboard[midpnt] <= 0) {				useroll(dice[0]);				useroll(dice[1]);				addintermediatepnt(midpnt, 0);				return(1);			}			message(ERR, "You cannot touch down on a blocked point!");			return(0);		}		if (to != HOME) {			message(ERR, "You didn't roll that move!");			return(0);		}		if (dice[0] > dice[1]) {			if (dice[0] > rollneeded) {				if (from != furthest) {					message(ERR, "You didn't roll that move!");					return(0);				}				useroll(dice[0]);				return(1);			}		} else {			if (dice[1] > rollneeded) {				if (from != furthest) {					message(ERR, "You didn't roll that move!");					return(0);				}				useroll(dice[1]);				return(1);			}		}		if (numdice < 2) {			message(ERR, "You didn't roll that move!");			return(0);		}		if (dice[0] + dice[1] > rollneeded) {			if (from != furthest) {				message(ERR, "You didn't roll that move!");				return(0);			}			midpnt = from - (humandieroll[0] & NUMMASK);			for (furthest = 6; furthest > 1; furthest--) {				if (humanboard[furthest] > 0 && !(furthest == from && humanboard[from] == 1))					break;			}			if (midpnt != furthest) {				message(ERR, "You didn't roll that move!");				return(0);			}			if (computerboard[midpnt] == 1) {				useroll(dice[0]);				useroll(dice[1]);				addintermediatepnt(midpnt, 1);				return(1);			}			if (computerboard[midpnt] <= 0) {				useroll(dice[0]);				useroll(dice[1]);				addintermediatepnt(midpnt, 0);				return(1);			}			midpnt = from - (humandieroll[1] & NUMMASK);			if (midpnt != furthest) {				message(ERR, "You didn't roll that move!");				return(0);			}			if (computerboard[midpnt] == 1) {				useroll(dice[0]);				useroll(dice[1]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -