void MetalStyle::drawMetalFrame( QPainter *p, int x, int y, int w, int h ) const { QColor top1("#878769691515"); QColor top2("#C6C6B4B44949"); QColor bot2("#70705B5B1414"); QColor bot1("#56564A4A0E0E"); //first from the bottom int x2 = x + w - 1; int y2 = y + h - 1; //frame: p->setPen( top1 ); p->drawLine( x, y2, x, y ); p->drawLine( x, y, x2-1, y ); p->setPen( top2 ); p->drawLine( x+1, y2 -1, x+1, y+1 ); p->drawLine( x+1, y+1 , x2-2, y+1 ); p->setPen( bot1 ); p->drawLine( x+1, y2, x2, y2 ); p->drawLine( x2, y2, x2, y ); p->setPen( bot2 ); p->drawLine( x+1, y2-1, x2-1, y2-1 ); p->drawLine( x2-1, y2-1, x2-1, y+1 ); }
void loop() { delay(1000); isBot1 = digitalRead(BOT_SWITCH); bot1(); digitalWrite(TRANSMIT_PIN, LOW); while (1); /* stop forever */ }
void display() { /* This function is used to display the content on to the screen... This is not important for the participant... He can skip it */ int gridDup[6][7],moveDup=move,endGameFlagDup,rowNum; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); drawGrid(grid); if(animate) { drawPiece(result,displacement,move); if(stopAnimate(grid,result,displacement)) { animate=0; if(!errorFlag) { rowNum=updateGrid(move,grid,result); // update the grid implying the move has been made drawGrid(grid); if(checkWinOrLose(grid,result,rowNum)) { // check for win condition win=move; // win will contain which bot has won endGameFlag=1; } else if(checkDraw(grid)) { // check for draw condition win=0; // win=0 implies draw endGameFlag=1; } move*=-1; // toggle between plaper 1 and player 2 } } } if(errorFlag) // If error occurs text(displayStr,-1.5,-1.8,font3); if(endGameFlag) { // If game ends if(win>0) // player 1 wins strcpy(displayStr,"Bot 1 wins!!!"); else if(win<0) // player 2 wins strcpy(displayStr,"Bot 2 wins!!!"); else // draw strcpy(displayStr,"Game drawn!!!"); text(displayStr,-1.5,-1.8,font3); printf("\n\n\t%s\n\n\t\tgrid content : \n\n",displayStr); displayStatus(grid); } glFlush(); glutSwapBuffers(); if(animate) displacement+=0.005; if(!endGameFlag && !errorFlag && !animate) { copyGrid(grid,gridDup); moveDup=move; endGameFlagDup=endGameFlag; if(move>0) result=bot1(grid,move); else result=bot2(grid,move); if(!(equalGrid(grid,gridDup) && move==moveDup && endGameFlagDup==endGameFlag)) { // grid() and move variables should not be changed sprintf(displayStr,"Bot %d error : Grid or move is modified!!!",move); errorFlag=1; } checkForErrors(result,move,grid); // errors like result should be within the 0 to 6 range, etc... animate=1; displacement=0; } }
/****************************************************************** *ux,uy coordinates of U *ex,ey coordinates of E *engine2 controls game play ,calls bot, changes position of bot and * makes the new maze ready for the next player. *done =0 till R is not visited * 1 if R is reached(Game over) ************************************************************************/ void engine2(int** Maze,char** maze,int N,int score_U,int score_E,int ux,int uy,int ex,int ey, int bot_num1, int bot_num2){ int done=0; int p; switch(bot_num1){ //calls the respective bots case(1): p=bot1(Maze,maze,N,score_U,score_E,ux,uy,ex,ey); break; case(2): p=bot2(Maze,maze,N,score_U,score_E,ux,uy,ex,ey); break; case(3): p=bot3(Maze,maze,N,score_U,score_E,ux,uy,ex,ey); break; } //making changes in maze by moving U to the new position if(ux==ex && uy==ey) maze[ux][uy]='E';//case when U and E overlap else maze[ux][uy]='.'; if(p==0) ux--; else if(p==1) uy++; else if(p==2) ux++; else uy--; score_U += Maze[ux][uy]; Maze[ux][uy]=0; if(maze[ux][uy]=='R') //check if the game is over done=1; maze[ux][uy]='U'; printmaze2(maze,N,score_U,score_E,done,'U'); if(done==0)//if the game is not done calls next player { switch(bot_num2){ case(1): p=bot1(Maze,maze,N,score_U,score_E,ex,ey,ux,uy); break; case(2): p=bot2(Maze,maze,N,score_U,score_E,ex,ey,ux,uy); break; case(3): p=bot3(Maze,maze,N,score_U,score_E,ex,ey,ux,uy); break; } //making changes in maze by moving E to the new position if(ex==ux && ey== uy) maze[ex][ey]='U'; else maze[ex][ey]='.'; if(p==0) ex--; else if(p==1)ey++; else if(p==2)ex++; else ey--; score_E += Maze[ex][ey]; Maze[ex][ey]=0; if(maze[ex][ey]=='R') done=1; maze[ex][ey]='E'; printmaze2(maze,N,score_U,score_E,done,'E'); if(done!=1)//continue the game if its not done engine2(Maze,maze,N,score_U,score_E,ux,uy,ex,ey,bot_num1,bot_num2); } }