View unanswered posts | View active topics It is currently Tue Dec 11, 2018 7:00 am

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Game in NXT
Author Message
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Game in NXT
Hello all... I really don't know the english name of this game, but i work on it during the afternoon, and i am happy to share to all of you.

Let me know...

 Code:#define xx 100#define yy 64#define size 20#define margem 10#define m 2#define shiftx 16#define shifty 0const int xpeca[] = {   (xx-size)/2-size+5+shiftx,  (xx-size)/2+5+shiftx,  (xx-size)/2+size+5+shiftx,};const int ypeca[] = {   yy-(margem/2)+2+shifty,  yy-(margem/2)-size+2+shifty,  yy-(margem/2)-size*2+2+shifty,};const int x0quad[] = {   (xx-size)/2-size+shiftx,  (xx-size)/2+shiftx,  (xx-size)/2+size+shiftx,};const int x1quad[] = {   (xx+size)/2-size+shiftx,  (xx+size)/2+shiftx,  (xx+size)/2+size+shiftx,};const int y0quad[] = {   (yy-size)/2 + size+shifty,   (yy-size)/2+shifty,   (yy-size)/2 - size+shifty,};const int y1quad[] = {   (yy+size)/2 + size+shifty,   (yy+size)/2+shifty,   (yy+size)/2 - size+shifty,};int pecas[] = {  0,  0,  0,  0,  0,  0,  0,  0,  0,};int winner=0;bool draw=false;bool verifica(int jog){   //Combinations to win   // 0,1,2   ou  3,4,5  ou  6,7,8   // 0,3,6   ou  1,4,7  ou  2,5,8   // 0,4,8   ou  2,4,6   bool win= ( pecas[0] == pecas[1] && pecas[1]==pecas[2] && pecas[0]!=0)  ||             ( pecas[0] == pecas[3] && pecas[3]==pecas[6] && pecas[0]!=0)  ||             ( pecas[0] == pecas[4] && pecas[4]==pecas[8] && pecas[0]!=0)  ||            ( pecas[3] == pecas[4] && pecas[4]==pecas[5] && pecas[3]!=0)  ||            ( pecas[6] == pecas[7] && pecas[7]==pecas[8] && pecas[6]!=0)  ||            ( pecas[1] == pecas[4] && pecas[4]==pecas[7] && pecas[1]!=0)  ||            ( pecas[2] == pecas[5] && pecas[5]==pecas[8] && pecas[2]!=0)  ||            ( pecas[2] == pecas[4] && pecas[4]==pecas[6] && pecas[2]!=0);  if( win )   {      //WINNER      PlayTone(600,50);      wait1Msec(500);      winner=jog;      return true;   }   else   {      int x=0,t=1;      for(x=0;x<9;x++)      {         t*=pecas[x];      }      if(t!=0) //Draw Game, Start again!!      {       draw=true;         PlayTone(200,50);         wait10Msec(50);         return true;      }      else       return false;   }}bool novojogo(){   int p=1;   const int timeout=10000;   while(true)   {     eraseDisplay();     nxtDisplayCenteredTextLine(1,"NEW GAME?");    nxtDisplayCenteredBigTextLine(3,"YES  NO");    if(p==1)nxtDrawRect(2,21,47,21+22);    if(p==2)nxtDrawRect(52,21,95,21+22);    ClearTimer(T1);    while(nNxtButtonPressed==-1)//Wait for Press    {       nxtDisplayTextLine(6,"Escolha em: %d",(timeout-time1(T1))/1000);       if(time1(T1)>timeout)           return(p==1?true:false);    }    if(nNxtButtonPressed==1 || nNxtButtonPressed==2 )      {                 p=(p==1?2:1);    }    if(nNxtButtonPressed==3)      {         eraseDisplay();         wait1Msec(1000);         return(p==1?true:false);      }      while(nNxtButtonPressed!=-1);//Wait for Release  }}void exit(){     eraseDisplay();     while(nNxtButtonPressed!=-1);//Esperar por largar      int p=1;     const int timeout=10000;    ClearTimer(T1);    while(time1(T1)timeout)             {              if(p==1)              {                 StopAllTasks();              }               else               {                   while(nNxtButtonPressed!=-1);//Wait for release                  return;               }            }          }          if(nNxtButtonPressed==1 || nNxtButtonPressed==2 )            {               p=(p==1?2:1);          }          if(nNxtButtonPressed==3)            {               eraseDisplay();            if(p==1)            {                 StopAllTasks();            }            else            {                while(nNxtButtonPressed!=-1);//Wait for release               return;            }            }            if(nNxtButtonPressed==0)            {               StopAllTasks();            }            while(nNxtButtonPressed!=-1);//Wait for release     }}void anim(){   ClearTimer(T4);   while(time1(T4)<800)   {      nxtFillRect(10, 50, 10+time1(T4)/10, 10+50);   }   ClearTimer(T4);   while(time1(T4)<800)   {      nxtFillRect(xx/2-5, 50, xx/2+5 , 50 - time1(T4)/20 );   }   wait1Msec(500);   nxtDisplayStringAt(xx/2+10, 17, "Games");  wait1Msec(1500);   eraseDisplay();   ClearTimer(T4);   while(time1(T4)<2500)   {      nxtDrawCircle(0, yy, time1(T4)/10);      wait10Msec(10);   }   nxtDrawRect(xx/2-35, yy/2+5, xx/2+35, yy/2+5);   nxtEraseRect(xx/2-35, yy/2+5, xx/2+35, yy/2+5);  nxtDisplayStringAt(xx/2-33,yy/2+4,"JOGO DO GALO");//JOGO DO GALO <- Name   wait1Msec(2000);}task main(){   anim();   bool novo=true;   int ftp=(random(1000)%2)+1; //First To Play (1 or 2)  nNxtButtonTask  = -2;  nNxtExitClicks  = 3;   do{        eraseDisplay();        int i;        for(i=0;i<9;i++)pecas[i]=0;      draw=false;      winner=0;         int actual=0;         int jogadascount=0;         bool fim=false;        do        {            int i=0,j=0;            for(i=0;i<3;i++)            {              for(j=0;j<3;j++)              {                 if( pecas[i*3+j] == 1 ) nxtDisplayBigStringAt(xpeca[j], ypeca[i], "x");                 if( pecas[i*3+j] == 2 ) nxtDisplayBigStringAt(xpeca[j], ypeca[i], "o");                 nxtDrawRect( x0quad[j] , y0quad[i] , x1quad[j] , y1quad[i]);              }            }          int cact=actual/3;           int lact=actual%3;           if(pecas[actual]!=0) nxtFillRect( x0quad[lact]+m , y0quad[cact]+m , x1quad[lact]-m , y1quad[cact]-m);          else          {            if(ftp==1)nxtDisplayStringAt(xpeca[lact], ypeca[cact]-m, "x");              if(ftp==2) nxtDisplayStringAt(xpeca[lact], ypeca[cact]-m, "o");             nxtDrawRect( x0quad[lact]+m , y0quad[cact]+m , x1quad[lact]-m , y1quad[cact]-m);          }          nxtDisplayStringAt(5,yy-5,"P1:x");          nxtDisplayStringAt(5,yy-15,"P2:o");          if(ftp==1)nxtDisplayStringAt(2,30,"Agr:x");          if(ftp==2)nxtDisplayStringAt(2,30,"Agr:o");          nxtDisplayStringAt(2,10,"JOG:%d",jogadascount);          while(nNxtButtonPressed==-1);//waitClick         if(nNxtButtonPressed==0)           {             exit();           }           if(nNxtButtonPressed==1)           {             actual++;             actual%=9;           }           if(nNxtButtonPressed==2)           {             if(actual==0)                 actual=8;              else               actual--;           }           if(nNxtButtonPressed==3)           {              //Play it.              if(pecas[lact+cact*3]==0)              {                 pecas[lact+cact*3]=ftp;                 fim=verifica(ftp);                 ftp=(ftp==1?2:1);//Change Player                 jogadascount++;             }             else             {                  PlayTone(444,10);                   wait10Msec(10);             }           }           while(nNxtButtonPressed!=-1);           eraseDisplay();        }while(!fim);        wait1Msec(1000);        eraseDisplay();        if(!draw)        {              nxtDisplayCenteredTextLine(1,"The winner is");              if(winner==1) nxtDisplayBigStringAt(xpeca[1]-shiftx, ypeca[1]-shifty, "x");              if(winner==2) nxtDisplayBigStringAt(xpeca[1]-shiftx, ypeca[1]-shifty, "o");              nxtDisplayCenteredBigTextLine(5,"Player %d",winner);      }      else      {              nxtDisplayCenteredTextLine(1,"It's a");              nxtDisplayBigStringAt(xpeca[0]-shiftx, ypeca[1]-shifty, "x");              nxtDisplayBigStringAt(xpeca[2]-shiftx, ypeca[1]-shifty, "o");              nxtDisplayCenteredBigTextLine(5,"DRAW");        }        wait1Msec(3000);        novo=novojogo();      ftp=winner;    }while(novo);}

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712

Tue Sep 23, 2008 3:41 pm
Expert

Joined: Sat Sep 20, 2008 12:16 pm
Posts: 106
Location: Curently fighting aliens on P3X-828
Re: Game in NXT
You should reconize that it is tic-tac-toe.

_________________

Sorry, your program could not be downloaded. Please reboot your computer.
FTC Team #2959 Team Smash Bros CLICK HERE.(or click www)
 Quote:What the world needs is more geniuses with humility, there are so few of us left.

Agreed

Tue Sep 23, 2008 7:55 pm
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Re: Game in NXT
Yes, it's true =)

So, anyone try it?

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712

Wed Sep 24, 2008 6:00 pm
Expert

Joined: Sat Sep 20, 2008 12:16 pm
Posts: 106
Location: Curently fighting aliens on P3X-828
Re: Game in NXT
I did. Thats when I figured it out

_________________

Sorry, your program could not be downloaded. Please reboot your computer.
FTC Team #2959 Team Smash Bros CLICK HERE.(or click www)
 Quote:What the world needs is more geniuses with humility, there are so few of us left.

Agreed

Wed Sep 24, 2008 9:17 pm
Site Admin

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Game in NXT
I've been a little busy with non-Lego related stuff (*shock horror*) but I'm definately trying this out. I've been wanting a long time to make a simple neural network that "learns" which moves to make. I'll be sure to call it WOPR but I'll refrain from hooking it up to any ICBMs.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Thu Sep 25, 2008 1:12 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 5 posts ]

#### Who is online

Users browsing this forum: No registered users and 0 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.