* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: FloodIt (need C help)  (Read 2643 times)

0 Members and 1 Guest are viewing this topic.

Offline Unicorn

  • ??? ??? ??? ??? ???
  • Super User
  • CW Contest II - 2nd place
  • *
  • Join Date: Jan 2015
  • Location: ??? ??? ??? ??? ???
  • Posts: 2807
  • Post Rating Ratio: +5/-2
  • make :PICKACHUP: a thing!
    • Unicorn808
    • 114/11432
    • ??? ??? ??? ??? ???
  • Gender: Male
FloodIt (need C help)
« on: February 24, 2016, 11:52:53 pm »
I'm figuring out how to use C with the CE, so I decided to port this game.

I've got the displaying part down, with the absence of buttons to change the color you want, but that should be easy to implement.



I've been trying to figure out how to check the colors of the squares adjacent and how to change their colors. Currently I have this in mind:
Code: [Select]
Select color
Change top left color
If the color of an adjacent is color of last color, change to current color
increase turns
repeat
Do you think this works? I'm going to check using getpixel, and I'm starting to believe that I'm gonna need to have each square mapped using a variable. Suggestions would be welcome on how to do this!
« Last Edit: February 25, 2016, 04:09:27 am by DJ Omnimaga »


  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Offline xlibman

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18428
  • Post Rating Ratio: +93/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: FloodIt
« Reply #1 on: February 25, 2016, 04:09:10 am »
Glad to see you are learning C. I hope you have fun with that language :). Also the game seems interesting. I hope you can pull it off and hopefully can get help for your problem.
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Scipi

  • Full User
  • Domain Name Owner
  • CW 4x3 challenge - 3rd place
  • *
  • Join Date: Nov 2014
  • Location: Lost Town
  • Posts: 164
  • Post Rating Ratio: +1/-0
  • CodeKitten ^w^
    • s1ay3r44
    • Scipii
    • _Scipi
    • Scipi
    • ScipiSoftware
  • Gender: Male
Re: FloodIt (need C help)
« Reply #2 on: February 25, 2016, 07:18:57 am »
I would use an array to hold all the color data, and then index into it. This article may help you: http://www.geeksforgeeks.org/flood-fill-algorithm-implement-fill-paint/
  • Calculators owned: TI-83+, Nspire, Nspire CX, Casio Prizm




Offline aeTIos

  • Dabbler in C
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Original 5
  • Join Date: Nov 2014
  • Location: Ede, NL
  • Posts: 1049
  • Post Rating Ratio: +12/-0
  • hi
    • r_vdijk
    • /u/aetios
    • aetios
  • Gender: Male
Re: FloodIt (need C help)
« Reply #3 on: February 25, 2016, 09:37:50 am »
I was going to suggest what @Scipi suggested. That would make it a lot easier to check color data. Are you going to use F1 .. F5 for choosing the colors?
ceci n'est pas une signature

Offline Unicorn

  • ??? ??? ??? ??? ???
  • Super User
  • CW Contest II - 2nd place
  • *
  • Join Date: Jan 2015
  • Location: ??? ??? ??? ??? ???
  • Posts: 2807
  • Post Rating Ratio: +5/-2
  • make :PICKACHUP: a thing!
    • Unicorn808
    • 114/11432
    • ??? ??? ??? ??? ???
  • Gender: Male
Re: FloodIt (need C help)
« Reply #4 on: February 25, 2016, 11:38:04 pm »
Are you going to use F1 .. F5 for choosing the colors?
Yes, I will also probably have a selection using the arrow keys.

I would use an array to hold all the color data, and then index into it. This article may help you: http://www.geeksforgeeks.org/flood-fill-algorithm-implement-fill-paint/
Yeah, that is what Cemetech recommended as well, I'll try to get that working, though I'm not sure how well I will be able to...

And for the curious, some code:

Code: [Select]
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>
 
/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* CE Graphics C Library */
#include <graphc.h>
int x = 61;
int y = 4;
int color;
int r;
/* Main Function */
void main(void)
{
    /* Some variable intialization */

    gc_InitGraph();
    gc_SetColorIndex(255);
    gc_FillScrn(0);
    gc_NoClipRectangleOutline(60,2,258,195);
    while (1) {
        r = rand() % 6;
        if (r == 0)
            color = 224; //RED
        if (r == 1)
            color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
           
        gc_SetColorIndex(color);   
        gc_NoClipRectangle(x,y,16,16);
        x += 16;
            if (x >= 305) {
                x = 61;
                y += 16;
            }
        if (y >= 192)
            break;
    }


    /* Print a string of stuff */
    gc_PrintStringXY("CircleStuff",1,250);
     
    /* This is a really bad function to use. Don't use it in actual things */
    _OS( GetKey() );

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Offline Scipi

  • Full User
  • Domain Name Owner
  • CW 4x3 challenge - 3rd place
  • *
  • Join Date: Nov 2014
  • Location: Lost Town
  • Posts: 164
  • Post Rating Ratio: +1/-0
  • CodeKitten ^w^
    • s1ay3r44
    • Scipii
    • _Scipi
    • Scipi
    • ScipiSoftware
  • Gender: Male
Re: FloodIt (need C help)
« Reply #5 on: February 26, 2016, 03:13:06 am »
I would use an array to hold all the color data, and then index into it. This article may help you: http://www.geeksforgeeks.org/flood-fill-algorithm-implement-fill-paint/
Yeah, that is what Cemetech recommended as well, I'll try to get that working, though I'm not sure how well I will be able to...

The code on that site looks like valid C, so you could use it more or less verbatim, provided all your color data is in a 2D array of ints.
  • Calculators owned: TI-83+, Nspire, Nspire CX, Casio Prizm




Offline Unicorn

  • ??? ??? ??? ??? ???
  • Super User
  • CW Contest II - 2nd place
  • *
  • Join Date: Jan 2015
  • Location: ??? ??? ??? ??? ???
  • Posts: 2807
  • Post Rating Ratio: +5/-2
  • make :PICKACHUP: a thing!
    • Unicorn808
    • 114/11432
    • ??? ??? ??? ??? ???
  • Gender: Male
Re: FloodIt (need C help)
« Reply #6 on: February 27, 2016, 03:13:07 am »
I'm gonna try something myself first.

So I've added boxes and for selection, but my keyboard routine is way to fast. How would I go about slowing it down? I also need help with my randomizing. Mateo told me to seed it with srand(*(unsigned long*)0xF30044); but when I put that above the rand() % 6; code, it fills the box with one color that changes each time. What am I doing wrong?


Keyboard code:
Code: [Select]
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 10;
}
if (key & kb_Right && selectorX < 215+62) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 10;
}
kb_Reset();
}

Entire Code
Code: [Select]
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>
 
/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* CE Graphics C Library */
#include <graphc.h>
#include <keypadc.h>
int x = 61;
int y = 4;
int color;
int r;
int lastColor;
int key;
int selectorX = 65+11;
unsigned int speed;
void delay(unsigned int);
/* Main Function */
void main(void)
{
    /* Some variable intialization */

    gc_InitGraph();
    gc_SetColorIndex(255);
    gc_FillScrn(0);
gc_NoClipRectangleOutline(60,2,258,195);
gc_NoClipRectangleOutline(65+11,205,25,25);
gc_NoClipRectangleOutline(95+21,205,25,25);
gc_NoClipRectangleOutline(125+31,205,25,25);
gc_NoClipRectangleOutline(155+41,205,25,25);
gc_NoClipRectangleOutline(185+51,205,25,25);
gc_NoClipRectangleOutline(215+61,205,25,25);
gc_SetColorIndex(224);
gc_NoClipRectangle(65+12,206,23,23);
gc_SetColorIndex(16);
gc_NoClipRectangle(95+22,206,23,23);
gc_SetColorIndex(231);
gc_NoClipRectangle(125+32,206,23,23);
gc_SetColorIndex(5);
gc_NoClipRectangle(155+42,206,23,23);
gc_SetColorIndex(112);
gc_NoClipRectangle(185+52,206,23,23);
gc_SetColorIndex(227);
gc_NoClipRectangle(215+62,206,23,23);
while (1) {
r = rand() % 6;
        if (r == 0)
            color = 224; //RED
        if (r == 1)
            color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
           
        gc_SetColorIndex(color);   
        gc_NoClipRectangle(x,y,16,16);
        x += 16;
            if (x >= 305) {
                x = 61;
                y += 16;
            }
        if (y >= 192)
break;
}
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 10;
}
if (key & kb_Right && selectorX < 215+62) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 10;
}
kb_Reset();
}


    /* Print a string of stuff */
    gc_PrintStringXY("CircleStuff",1,250);
     
    /* This is a really bad function to use. Don't use it in actual things */
    _OS( GetKey() );

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Offline xlibman

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18428
  • Post Rating Ratio: +93/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: FloodIt (need C help)
« Reply #7 on: February 27, 2016, 05:43:24 am »
I can't help you with the code since I don't know C, but would using a variable as a key delay work? For example, when pressing a key, it would set the variable to 10 and then it would count down to zero every loop and when it reaches zero then you can press a key again. You would probably need to make it so that the first delay is longer, though.
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Unicorn

  • ??? ??? ??? ??? ???
  • Super User
  • CW Contest II - 2nd place
  • *
  • Join Date: Jan 2015
  • Location: ??? ??? ??? ??? ???
  • Posts: 2807
  • Post Rating Ratio: +5/-2
  • make :PICKACHUP: a thing!
    • Unicorn808
    • 114/11432
    • ??? ??? ??? ??? ???
  • Gender: Male
Re: FloodIt (need C help)
« Reply #8 on: February 27, 2016, 05:32:07 pm »
I can't help you with the code since I don't know C, but would using a variable as a key delay work? For example, when pressing a key, it would set the variable to 10 and then it would count down to zero every loop and when it reaches zero then you can press a key again. You would probably need to make it so that the first delay is longer, though.
That is what I ended up doing, Kerm had written a description for PT_ on cemetech, and that helped me get things going. So now, I'm gonna start getting my flood-fill algorithm going, I may need some help with that at some point.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Offline Unicorn

  • ??? ??? ??? ??? ???
  • Super User
  • CW Contest II - 2nd place
  • *
  • Join Date: Jan 2015
  • Location: ??? ??? ??? ??? ???
  • Posts: 2807
  • Post Rating Ratio: +5/-2
  • make :PICKACHUP: a thing!
    • Unicorn808
    • 114/11432
    • ??? ??? ??? ??? ???
  • Gender: Male
Re: FloodIt (need C help)
« Reply #9 on: February 28, 2016, 07:04:46 pm »
bump.

I have fixed the above issues, I had the seed in a loop, and the key-presses were pretty easy to fix.

Anyways, I've gotten my array filled with the numbers of my colors (I hope), and I am about to move on to the flood-fill.
Check it out!
Code: [Select]
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>
 
/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* CE Graphics C Library */
#include <graphc.h>
#include <keypadc.h>
int x = 61;
int y = 4;
int r, seed = 13;
int arrayColumn, arrayRow;
int lastColor, color;
int key, key1, key2;
int selectorX = 65+11;
unsigned int speed = 4, keyPress;
int floodArray[12][16];
/* Main Function */
void main(void)
{
    /* Some variable intialization */

    gc_InitGraph();
    gc_SetColorIndex(255);
    gc_FillScrn(0);
gc_NoClipRectangleOutline(60,2,258,195);
gc_NoClipRectangleOutline(65+11,205,25,25);
gc_NoClipRectangleOutline(95+21,205,25,25);
gc_NoClipRectangleOutline(125+31,205,25,25);
gc_NoClipRectangleOutline(155+41,205,25,25);
gc_NoClipRectangleOutline(185+51,205,25,25);
gc_NoClipRectangleOutline(215+61,205,25,25);
gc_SetColorIndex(224);
gc_NoClipRectangle(65+12,206,23,23);
gc_SetColorIndex(16);
gc_NoClipRectangle(95+22,206,23,23);
gc_SetColorIndex(231);
gc_NoClipRectangle(125+32,206,23,23);
gc_SetColorIndex(5);
gc_NoClipRectangle(155+42,206,23,23);
gc_SetColorIndex(112);
gc_NoClipRectangle(185+52,206,23,23);
gc_SetColorIndex(227);
gc_NoClipRectangle(215+62,206,23,23);
gc_SetTextColor((0<<8)|255);
gc_PrintStringXY("FloodIt",1,1);
gc_PrintStringXY("by",1,15);
gc_PrintStringXY("Unicorn",1,30);
srand(*(unsigned long*)0xF30044);
while (1) {
r = rand() % 6;
        if (r == 0)
            color = 224; //RED
        if (r == 1)
            color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
           
        gc_SetColorIndex(color);   
        gc_NoClipRectangle(x,y,16,16);
x += 16;
floodArray[arrayColumn][arrayRow] = color;
if (x >= 305) {
arrayRow = 0;
            x = 61;
y += 16;
if (y >= 192)
break;
arrayColumn++;
}
arrayRow++;
}
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
if (keyPress % 45 == 0) {
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 40;
}
if (key & kb_Right && selectorX < 215+58) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 40;
}
if (key1 & kb_2nd && selectorX == 76) {
//check algorithm - RED
lastColor = color;
color = 224;

}
if (key1 & kb_2nd && selectorX == 116) {
//check algorithm - BLUE
lastColor = color;
color = 16;
}
if (key1 & kb_2nd && selectorX == 156) {
//check algorithm - YELLOW
lastColor = color;
color = 231;
}
if (key1 & kb_2nd && selectorX == 196) {
//check algorithm - GREEN
lastColor = color;
color = 5;
}
if (key1 & kb_2nd && selectorX == 236) {
//check algorithm - PURPLE
lastColor = color;
color = 112;
}
if (key1 & kb_2nd && selectorX == 276) {
//check algorithm - ORANGE
lastColor = color;
color = 227;
}
}

gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
key1 = kb_ScanGroup(kb_group_1);
gc_SetTransparentColor(30);
gc_SetTextColor(255);
gc_PrintStringXY("FloodIt",1,1);
gc_PrintStringXY("by",20,15);
gc_PrintStringXY("Unicorn",1,30);
keyPress++;
}

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}

  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Offline Jkolade936

  • All Around Coolio
  • Super User
  • Join Date: Jan 2016
  • Location: Horseheads, NY
  • Posts: 1515
  • Post Rating Ratio: +9/-1
  • I'm an unknown loner. I try to change that.
    • Jkolade936
    • My Sprites and Walrii Collection
  • Gender: Male
Re: FloodIt (need C help)
« Reply #10 on: February 28, 2016, 08:17:41 pm »
Nice! Looks like this is running much faster than the BASIC one I just tested. Can't wait for a release! ;D
  • Calculators owned: None of them. :'(
Does this qualify as a signature? 
The answer is "Sure."


Offline xlibman

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18428
  • Post Rating Ratio: +93/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: FloodIt (need C help)
« Reply #11 on: February 29, 2016, 07:04:56 am »
Good to hear, and looks nice Unicorn. By the way, does this key delay cause key detection issues? (keypresses not registering all the time) Or is it fine?
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Unicorn

  • ??? ??? ??? ??? ???
  • Super User
  • CW Contest II - 2nd place
  • *
  • Join Date: Jan 2015
  • Location: ??? ??? ??? ??? ???
  • Posts: 2807
  • Post Rating Ratio: +5/-2
  • make :PICKACHUP: a thing!
    • Unicorn808
    • 114/11432
    • ??? ??? ??? ??? ???
  • Gender: Male
Re: FloodIt (need C help)
« Reply #12 on: February 29, 2016, 11:12:16 pm »
Good to hear, and looks nice Unicorn. By the way, does this key delay cause key detection issues? (keypresses not registering all the time) Or is it fine?
Not really, and if it becomes a problem, I can shorted the delay easily.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Offline Unicorn

  • ??? ??? ??? ??? ???
  • Super User
  • CW Contest II - 2nd place
  • *
  • Join Date: Jan 2015
  • Location: ??? ??? ??? ??? ???
  • Posts: 2807
  • Post Rating Ratio: +5/-2
  • make :PICKACHUP: a thing!
    • Unicorn808
    • 114/11432
    • ??? ??? ??? ??? ???
  • Gender: Male
Re: FloodIt (need C help)
« Reply #13 on: March 01, 2016, 05:59:50 am »
So, right now, I have something of an algorithm, though it doesn't do the job correctly. (screenshot below) Any tips on how to fix it up? I'll be taking more of a look at it tomorrow, so hopefully I can get more done with a fresh mind :)



Pseudocode of what it is supposed to do:
Code: [Select]
If 2nd pressed and Selector at RED and top left color doesn't equal red
     Set color RED
     Loop
          If last color equals the color of the squares in the row
               Set color RED
               Change color of those squares
          If last color is not the same color next square in the row
               Change columns
               Set row to first one
          Increment row
          If row is 16
               go to next column
               Set row to first one
          If column is 12
               exit loop
     Repeat loop

Code: [Select]
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>
 
/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* CE Graphics C Library */
#include <graphc.h>
#include <keypadc.h>
int x = 61;
int y = 4;
int r, seed = 13;
int arrayColumn, arrayRow;
int lastColor, color;
int key, key1, key2;
int selectorX = 65+11;
unsigned int speed = 4, keyPress;
int floodArray[12][16], coordXArray[16], coordYArray[12];
/* Main Function */
void main(void)
{
coordYArray[0] = 4;
coordYArray[1] = 20;
coordYArray[2] = 36;
coordYArray[3] = 52;
coordYArray[4] = 68;
coordYArray[5] = 84;
coordYArray[6] = 100;
coordYArray[8] = 116;
coordYArray[9] = 132;
coordYArray[10] = 148;
coordYArray[11] = 164;
coordYArray[12] = 180;
coordXArray[0] = 61;
coordXArray[1] = 77;
coordXArray[2] = 93;
coordXArray[3] = 109;
coordXArray[4] = 125;
coordXArray[5] = 141;
coordXArray[6] = 157;
coordXArray[7] = 173;
coordXArray[8] = 189;
coordXArray[9] = 205;
coordXArray[10] = 221;
coordXArray[11] = 237;
coordXArray[12] = 253;
coordXArray[13] = 269;
coordXArray[14] = 285;
coordXArray[15] = 301;
coordXArray[16] = 317;

    gc_InitGraph();
    gc_SetColorIndex(255);
    gc_FillScrn(0);
gc_NoClipRectangleOutline(60,2,258,195);
gc_NoClipRectangleOutline(65+11,205,25,25);
gc_NoClipRectangleOutline(95+21,205,25,25);
gc_NoClipRectangleOutline(125+31,205,25,25);
gc_NoClipRectangleOutline(155+41,205,25,25);
gc_NoClipRectangleOutline(185+51,205,25,25);
gc_NoClipRectangleOutline(215+61,205,25,25);
gc_SetColorIndex(224);
gc_NoClipRectangle(65+12,206,23,23);
gc_SetColorIndex(16);
gc_NoClipRectangle(95+22,206,23,23);
gc_SetColorIndex(231);
gc_NoClipRectangle(125+32,206,23,23);
gc_SetColorIndex(5);
gc_NoClipRectangle(155+42,206,23,23);
gc_SetColorIndex(112);
gc_NoClipRectangle(185+52,206,23,23);
gc_SetColorIndex(227);
gc_NoClipRectangle(215+62,206,23,23);
gc_SetTextColor((0<<8)|255);
gc_PrintStringXY("FloodIt",1,1);
gc_PrintStringXY("by",1,15);
gc_PrintStringXY("Unicorn",1,30);
srand(*(unsigned long*)0xF30044);
while (1) {
r = rand() % 6;
        if (r == 0)
            color = 224; //RED
        if (r == 1)
            color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
           
        gc_SetColorIndex(color);   
        gc_NoClipRectangle(x,y,16,16);
x += 16;
floodArray[arrayColumn][arrayRow] = color;
coordXArray[arrayRow] = x;
coordYArray[arrayColumn] = y;
if (x >= 305) {
arrayRow = 0;
            x = 61;
y += 16;
if (y >= 192)
break;
arrayColumn++;
}
arrayRow++;
}
arrayRow = 0;
arrayColumn = 0;
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
if (keyPress % 45 == 0) {
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 40;
}
if (key & kb_Right && selectorX < 215+58) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 40;
}
lastColor = color;
if (key1 & kb_2nd && selectorX == 76 && lastColor != 224) {
//check algorithm - RED
color = 224;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 116 && lastColor != 16) {
//check algorithm - BLUE
color = 16;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 156 && lastColor != 231) {
//check algorithm - YELLOW
color = 231;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 196 && lastColor != 5) {
//check algorithm - GREEN
color = 5;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 236 && lastColor != 112) {
//check algorithm - PURPLE
color = 112;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 276 && lastColor != 227) {
//check algorithm - ORANGE
color = 227;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
}
gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
key1 = kb_ScanGroup(kb_group_1);
gc_SetTransparentColor(30);
gc_SetTextColor(255);
gc_PrintStringXY("FloodIt",1,1);
gc_PrintStringXY("by",20,15);
gc_PrintStringXY("Unicorn",1,30);
keyPress++;
arrayRow = 0;
arrayColumn = 0;
}

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}
EDIT: Updated code with a few fixes, but it still does pretty much the same thing.
« Last Edit: March 01, 2016, 08:36:47 pm by Unicorn »
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Offline xlibman

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18428
  • Post Rating Ratio: +93/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: FloodIt (need C help)
« Reply #14 on: March 07, 2016, 06:24:10 am »
@Unicorn have you gotten any luck solving this so far? It seems that not many people here are able to help or maybe you should make a separate C topic about flood filling, but have you chedked tutorials on flood filling in the meantime?
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games