Beispiel #1
0
int
main(int argc, char *argv[])
{
    if (argc > 1) {
	railroad(argv + 1);
    } else {
	static char world[] = "Hello World";
	static char *hello[] =
	{world, 0};
	railroad(hello);
    }
    ExitProgram(EXIT_SUCCESS);
}
// this function handles players moving around the board
void move(struct player * players, struct location * board, const int n, int * pvalue, char * plocation)
{
    struct player * p = &players[n];
    int ret;
#ifdef DEBUG
    fprintf(output[globalrank], "Player %d moved from %d\n", n, p->location);
#endif
    // check to see if on the "go to jail" cell
    if (p->location == 30)
    {
        // go to jail
        p->location = 10;
        board[p->location].visited++;
        p->money -= 50;
        return;
    }
    else
    {
        // advance the player
        p->location += roll() + roll();
    }
    // check to see if player passed go
    if (p->location > 39)
    {
#ifdef DEBUG
        fprintf(output[globalrank], "Player %d passed Go\n", n);
#endif
        p->location %= 40;
        p->money += 200;
    }
#ifdef DEBUG
    fprintf(output[globalrank], " to %d\n", p->location);
#endif
    board[p->location].visited++;
    switch (p->location)
    {
        case 1:
        case 3:
        case 6:
        case 8:
        case 9:
        case 11:
        case 13:
        case 14:
        case 16:
        case 18:
        case 19:
        case 21:
        case 23:
        case 24:
        case 26:
        case 27:
        case 29:
        case 31:
        case 32:
        case 34:
        case 37:
        case 39:
            // properties
            property(players, board, n, pvalue, plocation);
            break;
        case 2:
        case 17:
        case 33:
            comm_chest(players, n);
            break;
        case 7:
        case 22:
        case 36:
            // 1 is property
            // 2 is utility pay 10x
            // 3 is railroad pay 2x
            // 4 is handle movement
            // 5 is railroad pay norm
            // chance
            ret = chance(players, n);
            switch (ret)
            {
                case 1:
                    property(players, board, n, pvalue, plocation);
                    break;
                case 2:
                    utility(players, board, 10, n, pvalue, plocation);
                    break;
                case 3:
                    railroad(players, board, 2, n, pvalue, plocation);
                    break;
                case 4:
                    move(players, board, n, pvalue, plocation);
                    break;
                case 5:
                    railroad(players, board, 1, n, pvalue, plocation);
                    break;
            }
            break;
        case 5:
        case 15:
        case 25:
        case 35:
            railroad(players, board, 1, n, pvalue, plocation);
            // railroad
            break;
        case 12:
        case 28:
            utility(players, board, 1, n, pvalue, plocation);
            // utility
            break;
        case 30:
            p->location = 10;
            p->money -= 50;
            // go to jail
            break;
        case 10:
            // jail
            break;
        case 4:
            p->money -= 200;
            // income tax
            break;
        case 38:
            p->money -= 75;
            // luxury tax
            break;
        case 0:
        case 20:
            // go and free parking, do nothing
            return;
        default:
            fprintf(stderr, "ERROR: where are you??? player %d at %d\n", p->order, p->location);
            break;
    }
}