/* *Some of the internal datatypes used * Copyright (C) 2005 Joseph Pingenot This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "options.h" #include "datatypes.h" /*Initialize the game*/ void init_game(struct cribserv_options *opts, struct game *g) { /*First, initialize the cards*/ int i; int j; /*suitloop*/ for(i=0; i < 4; i++) { /*faceloop*/ for(j=0; j < 13; j++) { //((g->cards)[i + j*4]).suit = all_possible_suits[i]; ((g->cards)[i + j*4]).suit = i; ((g->cards)[i + j*4]).face = j; ((g->cards)[i + j*4]).used = 0; ((g->cards)[i + j*4]).owner = NULL; } } for(i=0; i < 4; i++) { /*Initialize this player*/ g->players[i].nick[0] = '\0'; g->players[i].fd = -1; for(j = 0; j < 6; j++) { g->players[i].cards[j] = NULL; } g->players[i].dealer = 0; g->players[i].mugcheck = 0; g->players[i].agree = 0; g->players[i].used_cards = 0; g->players[i].score = 0; /*While we're looping, set the crib cards too*/ g->crib[i] = NULL; } g->topcard = NULL; g->tally = 0; /*n has not been set yet*/ g->n = -1; /*And set the options*/ g->opts = opts; } /*Resets counters for the next loop (play + coutning session); called at the * start of the hand filtering stage*/ void reset_loop(struct game *g) { int i, j; g->topcard = NULL; g->tally = 0; for(i=0; i < 4; i++) { /*Initialize this player*/ g->players[i].nick[0] = '\0'; for(j = 0; j < 6; j++) { g->players[i].cards[j] = NULL; } g->players[i].mugcheck = 0; g->players[i].agree = 0; g->players[i].used_cards = 0; /*While we're looping, set the crib cards too*/ g->crib[i] = NULL; } } /*This doesn't erase a player; it just sets up the player's slot for a new player *this should be called when a player quits. */ void void_player(struct game *g, struct player *p) { p->nick[0] = '\0'; p->fd = -1; } /* *Useful bit of code I don't want to do away with. for(i = 0; i < 52; i++) { switch(the_game.cards[i].face) { case ACE: printf("Ace of"); break; case TWO: printf("Two of"); break; case THREE: printf("Three of"); break; case FOUR: printf("Four of"); break; case FIVE: printf("Five of"); break; case SIX: printf("Six of"); break; case SEVEN: printf("Seven of"); break; case EIGHT: printf("Eight of"); break; case NINE: printf("Nine of"); break; case TEN: printf("Ten of"); break; case JACK: printf("Jack of"); break; case QUEEN: printf("Queen of"); break; case KING: printf("King of"); break; default: printf("unknown face/"); } switch(the_game.cards[i].suit) { case DIAMONDS: printf(" diamonds\n"); break; case HEARTS: printf(" hearts\n"); break; case SPADES: printf(" spades\n"); break; case CLUBS: printf(" clubs\n"); break; default: printf(" unknown suit\n"); } } */