Lines Matching +full:ship +full:- +full:to
2 * Copyright 2018-2022,2023 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
25 * holders shall not be used in advertising or otherwise to promote the *
30 * bs.c - original author: Bruce Holloway
52 * Constants for tuning the random-fire algorithm. It prefers moves that
53 * diagonal-stripe the board with a stripe separation of srchstep. If
60 #define OTHER (1-turn)
79 /* how to position us on player board */
86 /* how to position us on cpu board */
91 #define CYINV(y) ((y) - CYBASE)
92 #define CXINV(x) (((x) - CXBASE) / 3)
102 #define MYBASE SYBASE - 1 /* diagram caption */
104 #define HYBASE SYBASE - 1 /* help area */
107 /* this will need to be changed if BWIDTH changes */
132 {1, 1, 0, -1, -1, -1, 0, 1};
134 {0, 1, 1, 1, 0, -1, -1, -1};
136 /* current ship position and direction */
141 char *name; /* name of the ship type */
142 int hits; /* how many times has this ship been hit? */
144 int length; /* length of ship */
145 int x, y; /* coordinates of ship start point */
188 /* end the game, either normally or due to signal */ in uninitgame()
246 MvAddStr(4, 29, "Welcome to Battleship!"); in intro()
259 MvAddStr(22, 27, "Hit any key to continue..."); in intro()
309 for (l = 0; l < ss->length; ++l) { in placeship()
310 int newx = ss->x + l * xincr[ss->dir]; in placeship()
311 int newy = ss->y + l * yincr[ss->dir]; in placeship()
313 board[b][newx][newy] = ss->symbol; in placeship()
316 AddCh(ss->symbol); in placeship()
319 ss->hits = 0; in placeship()
330 /* generate a valid random ship placement into px,py */ in randomplace()
334 ss->dir = rnd(2) ? dir_E : dir_S; in randomplace()
335 ss->x = rnd(BWIDTH - (ss->dir == dir_E ? ss->length : 0)); in randomplace()
336 ss->y = rnd(BDEPTH - (ss->dir == dir_S ? ss->length : 0)); in randomplace()
357 ss->x = in initgame()
358 ss->y = in initgame()
359 ss->dir = in initgame()
360 ss->hits = 0; in initgame()
361 ss->placed = FALSE; in initgame()
365 ss->x = in initgame()
366 ss->y = in initgame()
367 ss->dir = in initgame()
368 ss->hits = 0; in initgame()
369 ss->placed = FALSE; in initgame()
373 MvAddStr(PYBASE - 2, PXBASE + 5, "Main Board"); in initgame()
374 MvAddStr(PYBASE - 1, PXBASE - 3, numbers); in initgame()
376 MvAddCh(PYBASE + i, PXBASE - 3, (chtype) (i + 'A')); in initgame()
390 MvAddStr(PYBASE + BDEPTH, PXBASE - 3, numbers); in initgame()
391 MvAddStr(CYBASE - 2, CXBASE + 7, "Hit/Miss Board"); in initgame()
392 MvAddStr(CYBASE - 1, CXBASE - 3, numbers); in initgame()
394 MvAddCh(CYBASE + i, CXBASE - 3, (chtype) (i + 'A')); in initgame()
409 MvAddStr(CYBASE + BDEPTH, CXBASE - 3, numbers); in initgame()
412 "To position your ships: move the cursor to a spot, then"); in initgame()
414 "type the first letter of a ship type to select it, then"); in initgame()
418 "ship should be pointed. You may also type a ship letter"); in initgame()
420 "followed by `r' to position it randomly, or type `R' to"); in initgame()
427 MvAddStr(SYBASE + 2, SXBASE, "h-+-l 4-+-6"); in initgame()
442 /* figure which ships still wait to be placed */ in initgame()
450 prompt(1, "Type one of [%s] to pick a ship.", docked + 1); in initgame()
461 if (ss->symbol == c) in initgame()
464 prompt(1, "Type one of [hjklrR] to place your %s.", ss->name); in initgame()
479 beep(); /* simple to verify, unlikely to happen */ in initgame()
481 prompt(1, "Random-placing your %s", ss->name); in initgame()
485 ss->placed = TRUE; in initgame()
489 if (!ss->placed) { in initgame()
492 ss->placed = TRUE; in initgame()
496 ss->x = curx; in initgame()
497 ss->y = cury; in initgame()
502 ss->dir = dir_N; in initgame()
506 ss->dir = dir_S; in initgame()
510 ss->dir = dir_W; in initgame()
514 ss->dir = dir_E; in initgame()
521 ss->placed = TRUE; in initgame()
533 "To fire, move the cursor to your chosen aiming point "); in initgame()
545 (void) prompt(0, "Press any key to start...", ""); in initgame()
575 ny = cury + BDEPTH - 1; in getcoord()
588 nx = curx + BWIDTH - 1; in getcoord()
599 ny = cury + BDEPTH - 1; in getcoord()
600 nx = curx + BWIDTH - 1; in getcoord()
606 nx = curx + BWIDTH - 1; in getcoord()
611 ny = cury + BDEPTH - 1; in getcoord()
661 /* is this location on the selected zboard adjacent to a ship? */ in collidecheck()
694 xend = ss->x + (ss->length - 1) * xincr[ss->dir]; in checkplace()
695 yend = ss->y + (ss->length - 1) * yincr[ss->dir]; in checkplace()
700 error("Ship is hanging from the edge of the world"); in checkplace()
712 for (l = 0; l < ss->length; ++l) { in checkplace()
713 if (collidecheck(b, ss->y + l * yincr[ss->dir], ss->x + l * xincr[ss->dir])) { in checkplace()
717 error("There's already a ship there"); in checkplace()
723 error("Er, Admiral, what about the other ship?"); in checkplace()
740 if (ss->length > ss->hits) in awinna()
745 return (-1); in awinna()
750 /* register a hit on the targeted ship */ in hitship()
761 if (ss->symbol == sym) { in hitship()
762 if (++ss->hits < ss->length) /* still afloat? */ in hitship()
770 for (j = -1; j <= 1; j++) { in hitship()
771 int bx = ss->x + j * xincr[(ss->dir + 2) % dir_MAX]; in hitship()
772 int by = ss->y + j * yincr[(ss->dir + 2) % dir_MAX]; in hitship()
774 for (i = -1; i <= ss->length; ++i) { in hitship()
777 x1 = bx + i * xincr[ss->dir]; in hitship()
778 y1 = by + i * yincr[ss->dir]; in hitship()
800 for (i = 0; i < ss->length; ++i) { in hitship()
801 int x1 = ss->x + i * xincr[ss->dir]; in hitship()
802 int y1 = ss->y + i * yincr[ss->dir]; in hitship()
804 hits[turn][x1][y1] = ss->symbol; in hitship()
807 AddCh(ss->symbol); in hitship()
836 prompt(1, "Where do you want to shoot? ", ""); in plyturn()
871 m = " My %s has gone to Davy Jones's locker!"; in plyturn()
874 m = " Glub, glub -- my %s is headed for the bottom!"; in plyturn()
881 (void) printw(m, ss->name); in plyturn()
914 /* random-fire routine -- implements simple diagonal-striping strategy */ in randomfire()
953 --srchstep; in randomfire()
963 #define S_SUNK -1
978 (void) printw(" I've sunk your %s", ss->name); in cpufire()
1000 * unstructuredness below. The five labels are states which need to be held
1003 * The FSM is not externally reset to RANDOM_FIRE if the player wins. Instead,
1005 * game, then if found transition to RANDOM_FIRE.
1044 case HUNT_DIRECT: /* last shot hit, we're looking for ship's long axis */ in cputurn()
1054 goto refire; /* ...so we must random-fire */ in cputurn()
1059 for (; n > 1; n--) in cputurn()
1096 case REVERSE_JUMP: /* nail down the ship's other end */ in cputurn()
1144 for (j = 0; j < ss->length; j++) { in playagain()
1145 cgoto(ss->y + j * yincr[ss->dir], ss->x + j * xincr[ss->dir]); in playagain()
1146 AddCh(ss->symbol); in playagain()
1158 MvPrintw(1, (COLWIDTH - j) / 2, in playagain()
1161 prompt(2, (awinna())? "Want to be humiliated again, %s [yn]? " in playagain()
1162 : "Going to give me a chance for revenge, %s [yn]? ", your_name); in playagain()
1178 if (sp->hits >= sp->length) in scount()
1179 continue; /* dead ship */ in scount()
1195 ," -b play a blitz game" in usage()
1196 ," -c ships may be adjacent" in usage()
1197 ," -s play a salvo game" in usage()
1206 /* *INDENT-OFF* */
1208 /* *INDENT-ON* */ in VERSION_COMMON()
1215 while ((ch = getopt(argc, argv, OPTS_COMMON "bcs")) != -1) { in VERSION_COMMON()
1221 "Bad Arg: -b and -s are mutually exclusive\n"); in VERSION_COMMON()
1229 "Bad Arg: -s and -b are mutually exclusive\n"); in VERSION_COMMON()
1252 while (awinna() == -1) { in VERSION_COMMON()
1263 while (i--) { in VERSION_COMMON()
1265 if (cputurn() && awinna() != -1) in VERSION_COMMON()
1268 if (plyturn() && awinna() != -1) in VERSION_COMMON()
1274 while ((turn ? cputurn() : plyturn()) && awinna() == -1) { in VERSION_COMMON()