- FloodIt [84+ CE] [TI-BASIC]
- 26 Feb 2016 07:16:53 pm
- Last edited by Michael2_3B on 29 Mar 2016 07:35:50 am; edited 2 times in total
(Note: This is the TI-Basic remake of the game. If you're looking for the C version, check out Unicorn's Thread)
FloodIt
Inspired by Unicorn's C remake of the Flood-It game, I am now creating a version of it in pure Basic as well.
I pretty much have the core game down so far:
-randomly generated, hardcoded 14x14 table with 8 colors (it won't be hardcoded in the end obviously. also 14x14 will be max size)
-blinking cursor
-custom flood fill algorithm for recoloring
Just like the original game, you must move your cursor around and click on whatever color you want.
<<Download 2/27>>
<<Official Download>>
You are able to play all the way through, however the algorithm execution time + recolor rendering time makes it extremely unenjoyable. I am hoping someone can find a way to speed my algorithm up, or find a different algorithm to use that is faster.
My algorithm is custom made; it uses [F] as the matrix to hold the color of each square, and a same sized matrix [G] to hold values of 0 or 1 as to tell the program what squares to redraw in the end.
Pseudocode:
Code:
I am 99% sure this works, however I may have missed something when checking it. As I have said, this is very slow and either needs to be sped up somehow or replaced with a different algorithm.
Full Code:
Code:
FloodIt
Inspired by Unicorn's C remake of the Flood-It game, I am now creating a version of it in pure Basic as well.
I pretty much have the core game down so far:
-randomly generated, hardcoded 14x14 table with 8 colors (it won't be hardcoded in the end obviously. also 14x14 will be max size)
-blinking cursor
-custom flood fill algorithm for recoloring
Just like the original game, you must move your cursor around and click on whatever color you want.
<<Download 2/27>>
<<Official Download>>
You are able to play all the way through, however the algorithm execution time + recolor rendering time makes it extremely unenjoyable. I am hoping someone can find a way to speed my algorithm up, or find a different algorithm to use that is faster.
My algorithm is custom made; it uses [F] as the matrix to hold the color of each square, and a same sized matrix [G] to hold values of 0 or 1 as to tell the program what squares to redraw in the end.
Pseudocode:
Code:
If clicked_color is the same as top_left_color
return
Else
Scan each element of [F]
If that element is the same as the top_left_color and is adjacent to a 1 in matrix [G]
Store a 1 in the 2nd matrix at the same spot the current element being scanned is at
Repeat this scan once (to make sure to get spots that hadnt had a 1 adjacent to them yet)
Replace all elements of [F] where a 1 is in [G] with clicked_color, and redraw table at same time
I am 99% sure this works, however I may have missed something when checking it. As I have said, this is very slow and either needs to be sped up somehow or replaced with a different algorithm.
Full Code:
Code:
DelVar [F]{14,14->dim([F] //hardcoded 14x14; will change
StoreGDB 0
CoordOff:GridOff:AxesOff
BackgroundOff
0->Xmin:264->Xmax
0->Ymax:~164->Ymin
ClrDraw
Line(60,~10,60,~152,Black //hardcoded box for 14x14 table; will change
Line(60,~10,264-62,~10,Black
Line(60,~152,264-62,~152,Black
Line(264-62,~10,264-62,~152,Black
For(A,0,13
For(B,0,13
{Blue,Red,Magenta,Green,Orange,Navy,Yellow,Orange
Ans(randInt(1,8->C
C->[F](A+1,B+1
For(D,62+10B,71+10B,2
Line(D,~12-10A,D,~21-10A,1,C,2 //drawing the boxes. It takes 24s to draw whole board...
End
End
End
0->A:0->B
Repeat K=45
Repeat K
For(Z,1,20
getKey->K
If Ans:20->Z //if user presses enter, they don't have to wait for loops to finish
End
Pt-On(66+10A,~16-10B,3,MedGray
If not(K:Then
For(Z,1,20
getKey->K
If Ans:20->Z
End
End
Pt-On(66+10A,~16-10B,3,[F](B+1,A+1)
End
A+(K=26)(A<13)-(K=24)(A>0->A
B+(K=34)(B<13)-(K=25)(B>0->B
//FLOOD FILL ALGORITHM
If K=105 and [F](1,1)!=[F](B+1,A+1:Then //continue only if clicked color is not the same as top left color
[F](1,1->C //top left color stored into c
[F](B+1,A+1->D //clicked color stored into d
DelVar [G]{14,14->dim([G]
1->[G](1,1
For(Z,0,1 //scan matrix twice, for the reason stated in the pseudocode
For(I,1,14
For(J,1+(I=1),14
If [F](J,I)=C and ((J>1)[G](J-(J>1),I) or (I>1)[G](J,I-(I>1)) or (J<14)[G](J+(J<14),I) or (I<14)[G](J,I+(I<14 //if element equals top left color and there is a 1 adjacent to it in [G]
1->[G](J,I
End
End
End
For(I,1,14
For(J,1,14
If [G](J,I:Then
D->[F](J,I //replace values in matrix
For(Z,52+10I,61+10I,2
Line(Z,~2-10J,Z,~11-10J,1,D //recolor necessary boxes
End
End
End
End
DelVar [G] //save memory
End
End