back.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* $NetBSD: back.h,v 1.14 2004/01/27 20:30:28 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1980, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * @(#)back.h 8.1 (Berkeley) 5/31/93
  31. */
  32. #include <sys/types.h>
  33. #include <sys/uio.h>
  34. #include <fcntl.h>
  35. #include <signal.h>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <termios.h>
  40. #include <termcap.h>
  41. #include <unistd.h>
  42. #define rnum(r) (random()%r)
  43. #define D0 dice[0]
  44. #define D1 dice[1]
  45. #define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
  46. /*
  47. *
  48. * Some numerical conventions:
  49. *
  50. * Arrays have white's value in [0], red in [1].
  51. * Numeric values which are one color or the other use
  52. * -1 for white, 1 for red.
  53. * Hence, white will be negative values, red positive one.
  54. * This makes a lot of sense since white is going in decending
  55. * order around the board, and red is ascending.
  56. *
  57. */
  58. extern const char EXEC[]; /* object for main program */
  59. extern const char TEACH[]; /* object for tutorial program */
  60. extern int pnum; /* color of player:
  61. -1 = white
  62. 1 = red
  63. 0 = both
  64. 2 = not yet init'ed */
  65. extern char args[100]; /* args passed to teachgammon and back */
  66. extern int acnt; /* length of args */
  67. extern int aflag; /* flag to ask for rules or instructions */
  68. extern int bflag; /* flag for automatic board printing */
  69. extern int cflag; /* case conversion flag */
  70. extern int hflag; /* flag for cleaning screen */
  71. extern int mflag; /* backgammon flag */
  72. extern int raflag; /* 'roll again' flag for recovered game */
  73. extern int rflag; /* recovered game flag */
  74. extern int tflag; /* cursor addressing flag */
  75. extern int rfl; /* saved value of rflag */
  76. extern int iroll; /* special flag for inputting rolls */
  77. extern int board[26]; /* board: negative values are white,
  78. positive are red */
  79. extern int dice[2]; /* value of dice */
  80. extern int mvlim; /* 'move limit': max. number of moves */
  81. extern int mvl; /* working copy of mvlim */
  82. extern int p[5]; /* starting position of moves */
  83. extern int g[5]; /* ending position of moves (goals) */
  84. extern int h[4]; /* flag for each move if a man was hit */
  85. extern int cturn; /* whose turn it currently is:
  86. -1 = white
  87. 1 = red
  88. 0 = just quitted
  89. -2 = white just lost
  90. 2 = red just lost */
  91. extern int d0; /* flag if dice have been reversed from
  92. original position */
  93. extern int table[6][6]; /* odds table for possible rolls */
  94. extern int rscore; /* red's score */
  95. extern int wscore; /* white's score */
  96. extern int gvalue; /* value of game (64 max.) */
  97. extern int dlast; /* who doubled last (0 = neither) */
  98. extern int bar; /* position of bar for current player */
  99. extern int home; /* position of home for current player */
  100. extern int off[2]; /* number of men off board */
  101. extern int *offptr; /* pointer to off for current player */
  102. extern int *offopp; /* pointer to off for opponent */
  103. extern int in[2]; /* number of men in inner table */
  104. extern int *inptr; /* pointer to in for current player */
  105. extern int *inopp; /* pointer to in for opponent */
  106. extern int ncin; /* number of characters in cin */
  107. extern char cin[100]; /* input line of current move
  108. (used for reconstructing input after
  109. a backspace) */
  110. extern const char *const color[];
  111. /* colors as strings */
  112. extern const char *const *colorptr; /* color of current player */
  113. extern const char *const *Colorptr; /* color of current player, capitalized */
  114. extern int colen; /* length of color of current player */
  115. extern struct termios old, noech, bg_raw;/* original tty status */
  116. extern int curr; /* row position of cursor */
  117. extern int curc; /* column position of cursor */
  118. extern int begscr; /* 'beginning' of screen
  119. (not including board) */
  120. int addbuf(int);
  121. void backone(int);
  122. void bsect(int, int, int, int);
  123. void buflush(void);
  124. int canhit(int, int);
  125. int checkd(int);
  126. int checkmove(int);
  127. void clear(void);
  128. void clend(void);
  129. void cline(void);
  130. int count(void);
  131. void curmove(int, int);
  132. int dotable(char, int);
  133. void errexit(const char *) __attribute__((__noreturn__));
  134. void fancyc(int);
  135. void fboard(void);
  136. void fixcol(int, int, int, int, int);
  137. void fixpos(int, int, int, int, int);
  138. void fixtty(struct termios *);
  139. void getarg(char ***);
  140. int getcaps(const char *);
  141. void getmove(void);
  142. void getout(int) __attribute__((__noreturn__));
  143. void gwrite(void);
  144. void init(void);
  145. int last(void);
  146. int main(int, char *[]);
  147. int makmove(int);
  148. int movallow(void);
  149. void movback(int);
  150. void moverr(int);
  151. int movokay(int);
  152. void newline(void);
  153. void newpos(void);
  154. void nexturn(void);
  155. void norec(const char *) __attribute__((__noreturn__));
  156. void odds(int, int, int);
  157. void proll(void);
  158. int quit(void);
  159. int readc(void);
  160. void recover(const char *);
  161. void refresh(void);
  162. void roll(void);
  163. int rsetbrd(void);
  164. void save(int);
  165. int text(const char *const *);
  166. void wrboard(void);
  167. void wrbsub(void);
  168. void wrhit(int);
  169. void wrint(int);
  170. void writec(char);
  171. void writel(const char *);
  172. void wrscore(void);
  173. int yorn(char);