130201Sbostic /* 230201Sbostic * Copyright (c) 1982 Regents of the University of California. 3*33172Sbostic * All rights reserved. 4*33172Sbostic * 5*33172Sbostic * Redistribution and use in source and binary forms are permitted 6*33172Sbostic * provided that this notice is preserved and that due credit is given 7*33172Sbostic * to the University of California at Berkeley. The name of the University 8*33172Sbostic * may not be used to endorse or promote products derived from this 9*33172Sbostic * software without specific prior written permission. This software 10*33172Sbostic * is provided ``as is'' without express or implied warranty. 1130201Sbostic */ 1230201Sbostic 1330201Sbostic #ifndef lint 14*33172Sbostic static char sccsid[] = "@(#)init.c 5.2 (Berkeley) 12/29/87"; 15*33172Sbostic #endif /* not lint */ 1630201Sbostic 1730201Sbostic # include "mille.h" 1830201Sbostic 1930201Sbostic /* 2030201Sbostic * @(#)init.c 1.1 (Berkeley) 4/1/82 2130201Sbostic */ 2230201Sbostic 2330201Sbostic init() { 2430201Sbostic 2530201Sbostic reg PLAY *pp; 2630201Sbostic reg int i, j; 2730201Sbostic reg CARD card; 2830201Sbostic 2930201Sbostic bzero(Numseen, sizeof Numseen); 3030201Sbostic Numgos = 0; 3130201Sbostic 3230201Sbostic for (i = 0; i < 2; i++) { 3330201Sbostic pp = &Player[i]; 3430201Sbostic pp->hand[0] = C_INIT; 3530201Sbostic for (j = 0; j < NUM_SAFE; j++) { 3630201Sbostic pp->safety[j] = S_UNKNOWN; 3730201Sbostic pp->coups[j] = FALSE; 3830201Sbostic } 3930201Sbostic for (j = 1; j < HAND_SZ; j++) { 4030201Sbostic pp->hand[j] = *--Topcard; 4130201Sbostic if (i == COMP) { 4230201Sbostic account(card = *Topcard); 4330201Sbostic if (issafety(card)) 4430201Sbostic pp->safety[card - S_CONV] = S_IN_HAND; 4530201Sbostic } 4630201Sbostic } 4730201Sbostic pp->mileage = 0; 4830201Sbostic pp->hand_tot = 0; 4930201Sbostic pp->safescore = 0; 5030201Sbostic pp->coupscore = 0; 5130201Sbostic pp->can_go = FALSE; 5230201Sbostic pp->speed = C_INIT; 5330201Sbostic pp->battle = C_INIT; 5430201Sbostic pp->new_speed = FALSE; 5530201Sbostic pp->new_battle = FALSE; 5630201Sbostic for (j = 0; j < NUM_MILES; j++) 5730201Sbostic pp->nummiles[j] = 0; 5830201Sbostic } 5930201Sbostic if (Order) 6030201Sbostic sort(Player[PLAYER].hand); 6130201Sbostic Discard = C_INIT; 6230201Sbostic Finished = FALSE; 6330201Sbostic End = 700; 6430201Sbostic } 6530201Sbostic 6630201Sbostic shuffle() { 6730201Sbostic 6830201Sbostic reg int i, r; 6930201Sbostic reg CARD temp; 7030201Sbostic 7130201Sbostic for (i = 0; i < DECK_SZ; i++) { 7230201Sbostic r = roll(1, DECK_SZ) - 1; 7330201Sbostic if (r < 0 || r > DECK_SZ - 1) { 7430201Sbostic fprintf(stderr, "shuffle: card no. error: %d\n", r); 7530201Sbostic die(); 7630201Sbostic } 7730201Sbostic temp = Deck[r]; 7830201Sbostic Deck[r] = Deck[i]; 7930201Sbostic Deck[i] = temp; 8030201Sbostic } 8130201Sbostic Topcard = &Deck[DECK_SZ]; 8230201Sbostic } 8330201Sbostic 8430201Sbostic newboard() { 8530201Sbostic 8630201Sbostic register int i; 8730201Sbostic register PLAY *pp; 8830201Sbostic static int first = TRUE; 8930201Sbostic 9030201Sbostic if (first) { 9130201Sbostic werase(Board); 9230201Sbostic werase(Score); 9330201Sbostic mvaddstr(5, 0, "--HAND--"); 9430201Sbostic mvaddch(6, 0, 'P'); 9530201Sbostic mvaddch(7, 0, '1'); 9630201Sbostic mvaddch(8, 0, '2'); 9730201Sbostic mvaddch(9, 0, '3'); 9830201Sbostic mvaddch(10, 0, '4'); 9930201Sbostic mvaddch(11, 0, '5'); 10030201Sbostic mvaddch(12, 0, '6'); 10130201Sbostic mvaddstr(13, 0, "--BATTLE--"); 10230201Sbostic mvaddstr(15, 0, "--SPEED--"); 10330201Sbostic mvaddstr(5, 20, "--DECK--"); 10430201Sbostic mvaddstr(7, 20, "--DISCARD--"); 10530201Sbostic mvaddstr(13, 20, "--BATTLE--"); 10630201Sbostic mvaddstr(15, 20, "--SPEED--"); 10730201Sbostic mvwaddstr(Miles, 0, 0, "--MILEAGE--"); 10830201Sbostic mvwaddstr(Miles, 0, 41, "--MILEAGE--"); 10930201Sbostic Sh_discard = -1; 11030201Sbostic for (pp = Player; pp <= &Player[COMP]; pp++) { 11130201Sbostic for (i = 0; i < HAND_SZ; i++) 11230201Sbostic pp->sh_hand[i] = -1; 11330201Sbostic pp->sh_battle = -1; 11430201Sbostic pp->sh_speed = -1; 11530201Sbostic pp->sh_mileage = -1; 11630201Sbostic } 11730201Sbostic first = FALSE; 11830201Sbostic } 11930201Sbostic else { 12030201Sbostic for (i = 0; i < 5; i++) { 12130201Sbostic move(i, 0); 12230201Sbostic clrtoeol(); 12330201Sbostic } 12430201Sbostic wmove(Miles, 1, 0); 12530201Sbostic wclrtobot(Miles); 12630201Sbostic wmove(Board, MOVE_Y + 1, MOVE_X); 12730201Sbostic wclrtoeol(Board); 12830201Sbostic wmove(Board, MOVE_Y + 2, MOVE_X); 12930201Sbostic wclrtoeol(Board); 13030201Sbostic } 13130201Sbostic Sh_discard = -1; 13230201Sbostic for (pp = Player; pp <= &Player[COMP]; pp++) { 13330201Sbostic for (i = 0; i < NUM_SAFE; i++) 13430201Sbostic pp->sh_safety[i] = FALSE; 13530201Sbostic for (i = 0; i < NUM_MILES; i++) 13630201Sbostic pp->sh_nummiles[i] = 0; 13730201Sbostic pp->sh_safescore = -1; 13830201Sbostic } 13930201Sbostic newscore(); 14030201Sbostic } 14130201Sbostic 14230201Sbostic newscore() { 14330201Sbostic 14430201Sbostic reg int i, new; 14530201Sbostic register PLAY *pp; 14630201Sbostic static int was_full = -1; 14730201Sbostic static int last_win = -1; 14830201Sbostic 14930201Sbostic if (was_full < 0) 15030201Sbostic was_full = (Window != W_FULL); 15130201Sbostic stdscr = Score; 15230201Sbostic move(0, 22); 15330201Sbostic new = FALSE; 15430201Sbostic if (inch() != 'Y') { 15530201Sbostic erase(); 15630201Sbostic mvaddstr(0, 22, "You Comp Value"); 15730201Sbostic mvaddstr(1, 2, "Milestones Played"); 15830201Sbostic mvaddstr(2, 8, "Each Safety"); 15930201Sbostic mvaddstr(3, 5, "All 4 Safeties"); 16030201Sbostic mvaddstr(4, 3, "Each Coup Fourre"); 16130201Sbostic mvaddstr(2, 37, "100"); 16230201Sbostic mvaddstr(3, 37, "300"); 16330201Sbostic mvaddstr(4, 37, "300"); 16430201Sbostic new = TRUE; 16530201Sbostic } 16630201Sbostic else if (((Window == W_FULL || Finished) ^ was_full) || 16730201Sbostic pp->was_finished != Finished) { 16830201Sbostic move(5, 1); 16930201Sbostic clrtobot(); 17030201Sbostic new = TRUE; 17130201Sbostic } 17230201Sbostic else if (Window != last_win) 17330201Sbostic new = TRUE; 17430201Sbostic if (new) { 17530201Sbostic for (i = 0; i < SCORE_Y; i++) 17630201Sbostic mvaddch(i, 0, '|'); 17730201Sbostic move(SCORE_Y - 1, 1); 17830201Sbostic while (addch('_') != ERR) 17930201Sbostic continue; 18030201Sbostic for (pp = Player; pp <= &Player[COMP]; pp++) { 18130201Sbostic pp->sh_hand_tot = -1; 18230201Sbostic pp->sh_total = -1; 18330201Sbostic pp->sh_games = -1; 18430201Sbostic pp->sh_safescore = -1; 18530201Sbostic } 18630201Sbostic } 18730201Sbostic Player[PLAYER].was_finished = !Finished; 18830201Sbostic Player[COMP].was_finished = !Finished; 18930201Sbostic if (Window == W_FULL || Finished) { 19030201Sbostic if (!was_full || new) { 19130201Sbostic mvaddstr(5, 5, "Trip Completed"); 19230201Sbostic mvaddstr(6, 10, "Safe Trip"); 19330201Sbostic mvaddstr(7, 5, "Delayed Action"); 19430201Sbostic mvaddstr(8, 10, "Extension"); 19530201Sbostic mvaddstr(9, 11, "Shut-Out"); 19630201Sbostic mvaddstr(10, 21, "---- ---- -----"); 19730201Sbostic mvaddstr(11, 9, "Hand Total"); 19830201Sbostic mvaddstr(12, 20, "----- -----"); 19930201Sbostic mvaddstr(13, 6, "Overall Total"); 20030201Sbostic mvaddstr(14, 15, "Games"); 20130201Sbostic mvaddstr(5, 37, "400"); 20230201Sbostic mvaddstr(6, 37, "300"); 20330201Sbostic mvaddstr(7, 37, "300"); 20430201Sbostic mvaddstr(8, 37, "200"); 20530201Sbostic mvaddstr(9, 37, "500"); 20630201Sbostic } 20730201Sbostic } 20830201Sbostic else 20930201Sbostic if (was_full || new) { 21030201Sbostic mvaddstr(5, 21, "---- ---- -----"); 21130201Sbostic mvaddstr(6, 9, "Hand Total"); 21230201Sbostic mvaddstr(7, 20, "----- -----"); 21330201Sbostic mvaddstr(8, 6, "Overall Total"); 21430201Sbostic mvaddstr(9, 15, "Games"); 21530201Sbostic mvaddstr(11, 2, "p: pick"); 21630201Sbostic mvaddstr(12, 2, "u: use #"); 21730201Sbostic mvaddstr(13, 2, "d: discard #"); 21830201Sbostic mvaddstr(14, 2, "w: toggle window"); 21930201Sbostic mvaddstr(11, 21, "q: quit"); 22030201Sbostic if (!Order) 22130201Sbostic mvaddstr(12, 21, "o: order hand"); 22230201Sbostic else 22330201Sbostic mvaddstr(12, 21, "o: stop ordering"); 22430201Sbostic mvaddstr(13, 21, "s: save"); 22530201Sbostic mvaddstr(14, 21, "r: reprint"); 22630201Sbostic } 22730201Sbostic stdscr = Board; 22830201Sbostic was_full = (Window == W_FULL || Finished); 22930201Sbostic last_win = Window; 23030201Sbostic } 231