コード例 #1
0
ファイル: engine.cpp プロジェクト: mikedasuya/ds
int Engine::evaluateState(int ar[3][3]) {
	int columnC = column(ar, CROSS);
	int rowsC = rows(ar, CROSS);
	int diagnal = diagnals(ar, CROSS);
	int sum = columnC+rowsC+diagnal;
	printf ("\n ------total for cross-:%d:--\n", sum);fflush(stdout);
	columnC = column(ar, ZERO);
	rowsC = rows(ar, ZERO);
	diagnal = diagnals(ar, ZERO);
	int sumZ = columnC+rowsC+diagnal;
	printf ("\n ------total for  ZERO-:%d:--\n", sumZ);fflush(stdout);
    struct Param * p = computerWinCompulsion(ar);
    if ( p!= NULL) {
        printGame(ar);
        int row = p->row;
        int column = p->column;
        ar[row][column] = ZERO;
        struct Param * p1 = userWinCompulsion(ar);
        if ( p1 != NULL) {
            int ro = p1->row;
            int co = p1->column;
            ar[ro][co] = CROSS;
            if (doesUserWinsInNextMove(ar)) {
                printGame(ar);
                ar[ro][co] = 0;
                ar[row][column] = 0;
                return -20;
            } else {
                printf("\n ---does user wins in next move-- false -");fflush(stdout);
                ar[ro][co] = 0;
                ar[row][column] = 0;
            }

        } else {
           printf("\n -------User win compulsion p = NULL");fflush(stdout);
           ar[row][column] = 0;

        }
    } else {
           printf("\n -------Computer win compulsion p = NULL");fflush(stdout);
    }
    printGame(ar);
	printf ("\n ------difference-:%d:--\n", sum - sumZ);fflush(stdout);
    int ch;
//    scanf("%d", &ch);
	return sum - sumZ;
}
コード例 #2
0
ファイル: life.c プロジェクト: ztza/Class-Projects
int main(){
    initGame();
    while(1){
        printGame();
        advanceGame();
        fflush(stdin);
        sleep(1);
    }
    return 0;
}
コード例 #3
0
ファイル: game.cpp プロジェクト: suhhmin/comp-projects-1
// @author Andre Allan Ponce
// @author Computergeek01 (for the keyboard input stuff)
// @author Duoas (for more keyboard input stuff)
// url: http://www.cplusplus.com/forum/beginner/75529/
// url: http://www.cplusplus.com/forum/articles/7312/#msg33734
void Game::runGame(){
	bool running = true;
	HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
	DWORD NumInputs = 0;
	DWORD InputsRead = 0;
	INPUT_RECORD irInput;
	GetNumberOfConsoleInputEvents(hInput, &NumInputs);
	int old_state = 0;
	clock_t startTime = clock();
	while(running){
		//printGame();
		switch(state){
		case STATE_PRE_GAME:{
			createWorld();
			preGameInit();
			state = STATE_LEVEL_ONE;
			break;
		}
		case STATE_GAME_FINISH:{
			break;
		}
		case STATE_WAIT:{
			
			if(clock() - startTime > 20){ // it was too fast at one point
				state = old_state;
			}
			//*/
			//Sleep(1*1000);
			//state = old_state;
			break;
		}
		default:{
			printGame();
			do ReadConsoleInput( hInput, &irInput, 1, &InputsRead );
			while ((irInput.EventType != KEY_EVENT) || irInput.Event.KeyEvent.bKeyDown);
			//ReadConsoleInput(hInput, &irInput, 1, &InputsRead); 
			startTime = clock();
			Location* thisRoom = world[currX][currY];
			getKeyInput(irInput.Event.KeyEvent.wVirtualKeyCode, thisRoom);
			switch(state){
			case STATE_LEVEL_ONE:{
				old_state = STATE_LEVEL_ONE;
				state = STATE_WAIT;
				break;
			}
			}
			break;
		}
		}
	}
}
コード例 #4
0
ファイル: nim3.c プロジェクト: Robotregent/system-soft
int init(int game[]){
    int i, ans;
    srand(time(0));
    for (i=0; i<3; i++){
        game[i]=rand() % 6 + 5;
    }
    printGame(game);
    printf("Willst Du beginnen? (j/n):\n");
    i=1;
    do {
        ans = getchar();
        if (ans == 'n')
        {
            i=0;
            break;
        }
    } while (ans != '\n');
    return i;
}
コード例 #5
0
ファイル: game.c プロジェクト: horsetailfiddlehead/ee478
void pickMove(GlobalState* globalData) {
    static int displaymove = 0;
    if (game.monSel == 0) {
        selectCard(globalData);
    } else {
        if (displaymove == 0) {
            printAttackMenu(globalData, game.myMonster);
            prints(8, 5, WHITE, BLUE, "Please select an attack: ", 1);
            displaymove = 1;
        } else {
            if (((0x0A > globalData->keyPress) || (globalData->keyPress > 0x0C))) {
                globalData->keyStatus = 1;
                prints(8, 5, WHITE, BLUE, "                                                            ", 1);
                prints(8, 5, WHITE, BLUE, "Invalid attack input. Please select from the options below: ", 1);
            } else {
                displaymove = 0;
                globalData->keyStatus = 0;
                switch (globalData->keyPress) {
                    case 0x0A:
                        game.myMove = &game.myMonster->movelist[0];
                        break;
                    case 0x0B:
                        game.myMove = &game.myMonster->movelist[1];
                        break;
                    case 0xC:
                        game.myMove = &game.myMonster->movelist[2];
                        break;
                }
                game.monSel = 0;
                game.moveSel = 1;
                game.myMove->uses--;
                printGame(globalData);
            }
        }
    }
}
コード例 #6
0
ファイル: nim3.c プロジェクト: Robotregent/system-soft
int main (void){
    int game[3], turn, counter=1;
    turn = init(game);
    while (gameCount(game)>0){
        printf("Runde: %d\n",counter);
        printGame(game);
        if(turn){
            human(game);
        }
        else{
            bot(game);
        }
        printf("--------\n");
        turn = !turn;
        counter++;
    }
    if (turn){
        printf("Bot hat gewonnen :(\n");
    }
    else{
        printf("Glückwunsch, Du hast gewonnen!\n");
    }
    return 0;
}
コード例 #7
0
ファイル: game.c プロジェクト: horsetailfiddlehead/ee478
void singlePlayer(GlobalState* globalData) {
    static int tempScore = 0;
    static int transition = 0;
    static int movedone = 0;
    // First time playing?
    // Read first time from SRAM
    if (globalData->firstTime == TRUE) {
        if (globalData->newKeyboard) {
            printKeyboard(globalData, "NAME?", 5);
        } else {
            processKeyboard(globalData, game.name, 5);
        }
    }
    if (globalData->doneKeyboard) {
        globalData->firstTime = FALSE;


        if (globalData->newGame) {
            globalData->newGame = 0;
            // Setup new game
            setupGame();
            tempScore = 0;
            transition = 0;
            game.turn = rand() % 2;
            printGame(globalData);
            getCards(); // Assume cards already read by interrupts on switches (?)
        }


        // Wait till someone presses D to continue
        if (globalData->keyPress == 0x0D) {
            transition = 1;
        }

        // Begin game with computer
        if (transition) {
            if (!game.gameOver) {
                // Situation depends on game.turn
                if (game.turn) {
                    if (game.moveSel == 0) {
                        pickMove(globalData);
                    }
                    if (game.moveSel == 1) {

                        tempScore = game.oppScore;
                        game.oppScore = attack(game.myMove, game.myMonster, game.oppScore);
                        if (game.oppScore == tempScore) {
                            prints(0, 10, RED, BLACK, "                    ", 1);
                            prints(0, 18, RED, BLACK, "                    ", 1);
                            prints(0, 26, RED, BLACK, "                    ", 1);
                            prints(0, 10, RED, BLACK, "Missed!", 1);
                        } else {
                            prints(0, 10, RED, BLACK, "                    ", 1);
                            prints(0, 18, RED, BLACK, "                    ", 1);
                            prints(0, 26, RED, BLACK, "                    ", 1);
                            prints(0, 10, RED, BLACK, "Your", 1);
                            printrs(30, 10, RED, BLACK, game.myMonster->monsterName, 1);
                            prints(84, 10, RED, BLACK, "used", 1);
                            printrs(0, 18, RED, BLACK, game.myMove->moveName, 1);
                            prints(0, 26, RED, BLACK, "-    ", 1);
                            integerprint(6, 26, RED, BLACK, tempScore - game.oppScore, 1);
                        }
                        game.moveSel = 0;
                        movedone = 1;
                    }
                } else {
                    // Computer randomly picks a monster and attack
                    game.oppMonster = &myMonsterList[rand() % 3 ];
                    game.oppMove = &game.oppMonster->movelist[rand() % 3];
                    tempScore = game.myScore;
                    game.myScore = attack(game.oppMove, game.oppMonster, game.myScore);
                    if (game.myScore == tempScore) {
                        prints(0, 10, RED, BLACK, "                    ", 1);
                        prints(0, 18, RED, BLACK, "                    ", 1);
                        prints(0, 26, RED, BLACK, "                    ", 1);
                        prints(0, 10, RED, BLACK, "Enmy Missed!", 1);
                    } else {
                        prints(0, 10, RED, BLACK, "                    ", 1);
                        prints(0, 18, RED, BLACK, "                    ", 1);
                        prints(0, 26, RED, BLACK, "                    ", 1);
                        prints(0, 10, RED, BLACK, "Enmy", 1);
                        printrs(30, 10, RED, BLACK, game.oppMonster->monsterName, 1);
                        prints(84, 10, RED, BLACK, "used", 1);
                        printrs(0, 18, RED, BLACK, game.oppMove->moveName, 1);
                        prints(0, 26, RED, BLACK, "-    ", 1);
                        integerprint(6, 26, RED, BLACK, tempScore - game.myScore, 1);
                    }
                    movedone = 1;
                }

                if (movedone == 1) {
                    prints(0, 40, YELLOW, BLACK, "Your Score: ", 1);
                    prints(0, 55, YELLOW, BLACK, "     ", 1);
                    integerprint(0, 55, YELLOW, BLACK, game.myScore, 1);
                    prints(0, 70, WHITE, BLACK, "Opponent Score: ", 1);
                    prints(0, 85, WHITE, BLACK, "     ", 1);
                    integerprint(0, 85, WHITE, BLACK, game.oppScore, 1);
                    // Check game status
                    game.gameOver = gameStatus();
                    game.turn = !game.turn;
                    transition = 0;
                    movedone = 0;
                }
                //                if (game.gameOver == 1) {
                //                    if (globalData->newGame == 0) {
                //                        printResults();
                //                    }
                //                }
            } else {
                if (globalData->newGame == 0) {
                    printResults();
                }
            }
        }
        // Display results once there is a lost
    }
}
コード例 #8
0
ファイル: main.c プロジェクト: landm2000/sokoban
int main()
{
    char level_data_line[20*16];
    LEVELDATA this_level_data = {
        {&level_data_line[0],   &level_data_line[20], &level_data_line[40], &level_data_line[60],
         &level_data_line[80], &level_data_line[100],&level_data_line[120],&level_data_line[140],
         &level_data_line[160],&level_data_line[180],&level_data_line[200],&level_data_line[220],
         &level_data_line[240],&level_data_line[260],&level_data_line[280],&level_data_line[300]},
        19,11
    };
    // Initializations
    srvInit();  // services
    aptInit();  // applets
    hidInit();  // input
	gfxInitDefault();
//	gfxSet3D(true); // uncomment if using stereoscopic 3D
    gfxSetDoubleBuffering(GFX_TOP, true);
    gfxSetDoubleBuffering(GFX_BOTTOM, false);

    PrintConsole /*topScreen, */bottomScreen;
    consoleInit(GFX_BOTTOM, &bottomScreen);
//    consoleInit(GFX_TOP, &topScreen);
    clear_char_stack();
    int level = 0;
    int mode = MODE_INIT;
//    int mode_status  = 0;
    hcount = 0;

int timer = 0;
    // Main loop
    while (aptMainLoop())
    {
        hidScanInput();
        u32 kDown = hidKeysDown();
        u32 kUp   = hidKeysUp();
        u32 kHeld = hidKeysHeld();
        if (kDown & KEY_START){
            break; // break in order to return to hbmenu
        }

        if (mode == MODE_INIT){
//            consoleSelect(&topScreen);
//            printf("\033[2J");
            copyGame(level,&this_level_data);
            gspWaitForVBlank();
            printGame(&this_level_data);
            mode = MODE_GAME;
        }else if (mode == MODE_CLEAR){
            if ((kUp & KEY_A) || (kUp & KEY_B) || (kUp & KEY_X) || (kUp & KEY_Y)){
                level++;
                if (level >= sizeof(level_data)/sizeof(LEVELDATA)) {
                    mode = MODE_ALL_CLEAR;
                }else{
                    mode = MODE_INIT;
                }
            }
            if (level < sizeof(level_data)/sizeof(LEVELDATA)) {
                consoleSelect(&bottomScreen);
                printf("\033[2J");
                printf("\x1b[21;12HStage cleared!!");
                printf("\x1b[23;12HPush A to next Next Stage");
            }
        }else if (mode == MODE_ALL_CLEAR){
            level = 0;
            consoleSelect(&bottomScreen);
            printf("\033[2J");
            printf("\x1b[21;12HGame cleared!!!");
            printf("\x1b[23;12HPush Start to exit game");
            mode = MODE_NULL;
        }else if (mode == MODE_GAME){

        // Your code goes here


#ifdef DEBUG
consoleSelect(&bottomScreen);
if (timer%10==0){
//if (1    != 0){printf("\x1b[10;12HkUp  =%08x",(unsigned int)kUp);}
//if (1    != 0){printf("\x1b[11;12HkDown=%08x",(unsigned int)kDown);}
//if (1    != 0){printf("\x1b[12;12HkHeld=%08x",(unsigned int)kHeld);}
//printf("\x1b[22;12HKEY_CPAD_UP=%x",KEY_UP);
//printf("\x1b[23;12HKEY_CPAD_DN=%x",KEY_DOWN);
printf("\x1b[20;12HRest: [SELECT]");
printf("\x1b[22;12HExit: [START]");
printf("\x1b[24;12HTime: %08d",timer);
}
timer++;
#endif
            if (kDown != 0 || kHeld != 0){
                if (kDown & KEY_SELECT){
                    mode = MODE_INIT;
                }else{
                    moveMan(kDown, kHeld,level,&this_level_data);
                    if(checkCleared(&this_level_data,level)==0){ mode = MODE_CLEAR;}
                    gspWaitForVBlank();
                    draw_char_stack(this_level_data,spriteData, sizeof(spriteData)/sizeof(SPRITEDATA));
                }
            }else{
                gspWaitForVBlank();
            }
        }

        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    gfxExit();
    hidExit();
    aptExit();
    srvExit();
	return 0;
}