Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: meishe91 on July 26, 2010, 02:50:30 am

Title: Battle Ship
Post by: meishe91 on July 26, 2010, 02:50:30 am
Ok. So I decided to completely do a rewrite of my Battle Ship program because I thought it was to big and just wasn't satisfied with it. I was also to lazy to just go back and rework the code to work. But anywho, to the program.

I did succeed in making this one smaller by about 62 bytes while still making it better than the previous version (it stands at 990 bytes). It should work perfectly now but if anyone discovers a bug please let me know.

[2ND] - It is the enter button.
[ALPHA] - When setting the maps this is what flips it between vertical and horizontal movement.
[ENTER] - Used to exit the Pause after turns.

This version fixes the previous bugs that I knew about. Like I said before if you find one just tell me and I'll try to fix it.

I can't think of much else to say so I'll let you guys to it. Have fun and enjoy.

Here is the source code in case anyone else can find optimizations. I'm very tired so there is a chance I missed something.

Code: (Battle Ship Final) [Select]
ClrHome
"3221110000→Str2
"MH  →Str1
0identity(16→[A]
DelVar TDelVar SDelVar LRepeat S=20 and T=20
ClrHome
For(A,1,8
Output(A,9-8L,"++++++++
End
Output(1,9-8L,"PLAYER
Output(1,16-8L,L+1
1→X
1→Y
DelVar G1→R
Repeat R=11
Repeat K=21
For(A,0,expr(sub(Str2,R,1
Output(X+AG,Y+Anot(G)+8L,sub("* ",2-[A](X+AG,Y+Anot(G)+8L),1
End
If Ans=31
not(G→G
min(8-Gexpr(sub(Str2,R,1)),max(1,X+sum(DeltaList(K={25,34→X
min(8-not(G)expr(sub(Str2,R,1)),max(1,Y+sum(DeltaList(K={24,26→Y
For(A,0,expr(sub(Str2,R,1
Output(X+AG,Y+Anot(G)+8L,"*
End
Repeat Ans
getKey→K
End
End
DelVar HFor(A,0,expr(sub(Str2,R,1
H+[A](X+AG,Y+Anot(G)+8L→H
End
If not(H
Then
For(A,0,expr(sub(Str2,R,1
1→[A](X+AG,Y+Anot(G)+8L
End
If L
T+1+expr(sub(Str2,R,1→T
If not(L
S+1+expr(sub(Str2,R,1→S
R+1→R
End
End
not(L→L
End
1→X
Ans→Y
randInt(0,1→L
Lbl 1
Repeat S=0 xor T=0
ClrHome
For(A,1,8
Output(A,1+8L,"++++++++
End
Output(1,1+8L,"PLAYER
Output(1,8+8L,L+1
For(A,1,8
For(B,9-8L,16-8L
Output(A,B,sub(Str1,4-[A](A,B),1
End
End
1→X
9→Y
Repeat K=21
Output(X,Y-8L,sub(Str1,4-[A](X,Y-8L),1
min(8,max(1,X+sum(DeltaList(K={25,34→X
min(16,max(9,Y+sum(DeltaList(K={24,26→Y
Output(X,Y-8L,"S
Output(3,4+8L,sub("ABCDEFGH",X,1
Output(3,5+8L,Y-8
Repeat Ans
getKey→K
End
End
If 1<[A](X,Y-8L
Then
Output(5,1+8L,"TRY
Output(6,4+8L,"AGAIN
Pause
Goto 1
End
If not([A](X,Y-8L
Then
Output(5,3+8L,"MISS
3→[A](X,Y-8L
not(L→L
Pause
Goto 1
End
If 1=[A](X,Y-8L
Then
Output(5,3+8L,"HIT!
If L
T-1→T
If not(L
S-1→S
2→[A](X,Y-8L
not(L→L
Pause
End
End
End
DelVar [A]ClrHome
not(L→L
Output(4,5,"PLAYER
Output(4,12,L+1
Output(5,7,"WON!
Title: Re: Battle Ship
Post by: DJ Omnimaga on July 29, 2010, 02:19:43 am
Seems nice, I hope you can make it small enough to be included in Homescreen Game Pack :).

I will try this now.
Title: Re: Battle Ship
Post by: meishe91 on July 29, 2010, 02:22:45 am
Thanks, me too. I haven't spent a whole lot of time working on it yet. I have thought about maybe redoing it completely though, like starting from scratch.
Title: Re: Battle Ship
Post by: DJ Omnimaga on July 29, 2010, 02:24:34 am
Aaah ok. Hopefully you can make it faster, too. Keep in mind this is BASIC, though. In BASIC, sometimes you need to sacrify a considerable amount of speed to keep the filesize as small as possible.

Btw nice game :). The only issue I could find is how you can put ships on top of each others
Title: Re: Battle Ship
Post by: nemo on July 29, 2010, 02:35:30 am
some optimizations i spot really quickly:

Code: [Select]
{8,8→dim([A]
Ans→dim([B]
to
Code: [Select]
0identity(8->[A]
Ans->[B]

Code: [Select]
B+(K=34)-(K=25
min(8,max(1,Ans→B
C+(K=26)-(K=24
min(16,max(9,Ans→C
to
Code: [Select]
min(8,max(1,B+(K=34)-(K=25->B
min(16,max(9,C+(K=26)-(K=24->C

there's another strip of movement code you can do that to.

not sure if this works but...
Code: [Select]
If Ans=31
G+not(G)-(G=1→G
End
to
Code: [Select]
If Ans=31
not(G->G
End

from what i glance through, it seems that G can only hold the values 1 or 0, right? if so, all the spots i see you have (G=1) can be changed to to just G.

lastly,
Code: [Select]
Delvar[A]Delvar[B]

 aren't necessary with my proposed 0identity(8) code.

i'll have to test this out later




Title: Re: Battle Ship
Post by: meishe91 on July 29, 2010, 02:45:12 am
@DJ
Thanks, and ya I know. It's just a hard concept to keep small, fast or not :P I'll keep working on it though and do my best.

And ya, I don't really like that either. I'm trying to come up with ways to keep that from happening and still keep this small. I've got a couple ideas.

@nemo
Thanks! If I remember G is only used for the rotation routine so I believe that should work. As for the walking routine fix, wow...I never even thought about including that into the min(...,max( section. For that first one though, how does that work? I'm not familiar with the identity( command, though I'll look it up real fast too. Thanks again :)

Edit:
Never mind, I figured out the identity( thing :)
Title: Re: Battle Ship
Post by: nemo on July 29, 2010, 02:50:43 am
no, problem meishe! (:

identity(A) creates a matrix A rows by A columns, with every number being 0 except for the diagonals.
so identity(5) creates:
Code: [Select]
10000
01000
00100
00010
00001

in my trick you have 0identity(8), which creates an 8x8 matrix then multiplies it by 0, creating an 8x8 0-filled matrix (:

also, i'm curious: when you have a player move their pieces around, are you drawing the whole map every time they move?
Title: Re: Battle Ship
Post by: meishe91 on July 29, 2010, 02:54:45 am
no, problem meishe! (:

identity(A) creates a matrix A rows by A columns, with every number being 0 except for the diagonals.
so identity(5) creates:
Code: [Select]
10000
01000
00100
00010
00001

in my trick you have 0identity(8), which creates an 8x8 matrix then multiplies it by 0, creating an 8x8 0-filled matrix (:

also, i'm curious: when you have a player move their pieces around, are you drawing the whole map every time they move?

Ya, that's what TI|BD said, thanks. With that trick you also don't need the dim( commands.

Ya, each time you move it redraws the map. That is what makes the game so slow. It was the only way I could think of that could make it so you don't overwrite pieces and still keep it small :( That is the main issue I need to fix.
Title: Re: Battle Ship
Post by: nemo on July 29, 2010, 02:58:11 am
you have an X and Y variable that keeps track of the ship the player is placing, right? is there any way to just draw the part of the map the player is at, and the part of the map the player is going to once they press a button?
Title: Re: Battle Ship
Post by: meishe91 on July 29, 2010, 03:01:31 am
Actually yes, I believe. You probably just helped make this faster...by considerable amounts. I will try my tweak that I'm thinking of and see what I get.

Edit:
Good news:
The speed issue has been taken care of now :)

Bad news:
There are a few bugs now arising :(

2nd Edit:
Good news:
Fixed those bugs that appeared.
It is now tolerable to play.

Bad news:
Initial bugs are still there.
-Being able to overwrite a number while laying the field.
-Can continuously hit one spot and win in about 10 turns (also starts reading as a technical false-positive).
It is now 1052 bytes :( Which means it's even further away from HGP.

Here is the new source code:

Code: (Battle Ship Final v2) [Select]
DelVar ADelVar GDelVar DDelVar E"4332221111→Str2
"MH     →Str1
0identity(8→[A]
Ans→[B]
1→B
1→C
Repeat A=2
1→R
For(θ,1,8
Output(θ,9-8A,"********
End
Output(1,9-8A,"PLAYER
Output(1,16-8A,A+1
For(I,1,8
For(J,1,8
If A
Output(I,J+8,[B](B,C
If not(A
Output(I,J,[A](B,C
End
End
Repeat R=11
Repeat K=21
For(Q,0,expr(sub(Str2,R,1))-1
Output(B+QG,C+Qnot(G)+8A,(A=1)[B](B,C)+not(A)[A](B,C
End
If K=31
not(G→G
min(8-Gexpr(sub(Str2,R,1))+G,max(1,B+(K=34)-(K=25→B
min(8-not(G)expr(sub(Str2,R,1))+not(G),max(1,C+(K=26)-(K=24→C
For(Q,0,expr(sub(Str2,R,1))-1
Output(B+QG,C+Qnot(G)+8A,sub(Str2,R,1
End
Repeat Ans
getKey→K
End
End
For(Q,0,expr(sub(Str2,R,1))-1
If A
expr(sub(Str2,R,1→[B](B+Q(G=1),C+Qnot(G
If not(A
expr(sub(Str2,R,1→[A](B+Q(G=1),C+Qnot(G
End
R+1→R
End
A+1→A
1→B
Ans→C
End
1→B
9→C
DelVar ARepeat E>49 or D>49
ClrHome
For(I,1,8
For(J,1,8
If A
Output(I,J,sub(Str1,7-[A](I,J),1
If not(A
Output(I,J+8,sub(Str1,7-[B](I,J),1
End
End
For(θ,1,8
Output(θ,1+8A,"********
End
Output(1,1+8A,"PLAYER
Output(1,8+8A,A+1
Repeat K=21
If A
Output(B,C-8,sub(Str1,7-[A](B,C-8),1
If not(A
Output(B,C,sub(Str1,7-[B](B,C-8),1
min(8,max(1,B+(K=34)-(K=25→B
min(16,max(9,C+(K=26)-(K=24→C
Output(B,C-8A,"S
Output(3,4+8A,sub("ABCDEFGH",B,1
Output(3,5+8A,C-8
Repeat Ans
getKey→K
End
End
If A
Then
If [A](B,C-8
Then
D+[A](B,C-8→D
5→[A](B,C-8
Output(6,11,"HIT!
Else
6→[A](B,C-8
Output(7,11,"MISS
End
Else
If [B](B,C-8
Then
E+[B](B,C-8→E
5→[B](B,C-8
Output(6,3,"HIT!
Else
6→[B](B,C-8
Output(7,3,"MISS
End
End
Pause
A+not(A)-(A=1→A
End
ClrHome
Output(4,5,"PLAYER
Output(4,12,A
Output(5,7,"WON!
Title: Re: Battle Ship
Post by: DJ Omnimaga on July 29, 2010, 04:07:32 am
I wondered why the map was redrawn everytime, but I somehow thought it might be to avoid coding multiple routines or something, so when placing ships, you just used the same map drawing routine as the rest
Title: Re: Battle Ship
Post by: meishe91 on July 29, 2010, 04:12:30 am
Nah, it was just to help keep the map up-to-date so you didn't have random tiles missing or forget where something was and such. But, as you experienced, it lagged it down a whole lot.
Title: Re: Battle Ship
Post by: DJ Omnimaga on July 29, 2010, 06:09:48 pm
Aaah ok I see. Thanks for the info :)
Title: Re: Battle Ship
Post by: meishe91 on July 29, 2010, 07:24:35 pm
Yup, no problem.
Title: Re: Battle Ship
Post by: ztrumpet on August 02, 2010, 11:45:36 am
Wow!  This is wonderful!  Excellent job!  This is a really nice version of Battleship.  Quick, everyone try it! ;D
Title: Re: Battle Ship
Post by: meishe91 on August 02, 2010, 04:59:37 pm
Update:
So I have completely rewritten the game. I have fixed all the issues, I believe, and so far it is about 100 bytes less than it was. I have one bug that I'm working on right now then I will post the new one.
Title: Re: Battle Ship
Post by: yunhua98 on August 02, 2010, 05:39:26 pm
cool!  Do you think it will be small enough to put into ztrumpet's Homescreen Gamepack?

EDIT:  200th post!
Title: Re: Battle Ship
Post by: meishe91 on August 02, 2010, 05:52:46 pm
cool!  Do you think it will be small enough to put into ztrumpet's Homescreen Gamepack?

EDIT:  200th post!

Nah. Well technically it is but it will add almost a kilobyte to the program. I'm about to update the original post and upload this new one.

Edit:
The original post has been edited and the new version has been posted.
Title: Re: Battle Ship
Post by: shmibs on August 02, 2010, 06:19:20 pm
just tried it out, and i am impressed
i rarely play anything in basic anymore, but this one's a keeper. props =D
EDIT: i glanced through the code really quickly and didnt see any obvious optimizations (cept mebbe where you used 1->x:1->y and then later 1->x:ans->y), but i like i said i havent messed with basic in a while and never on a screen this large, so...
DOUBLE EDIT: here's the code
Code: [Select]
:ClrHome
:"3221110000→Str2
:"MH  →Str1
:0identity(16→[A]
:DelVar TDelVar SDelVar LRepeat S=20 and T=20
:ClrHome
:For(A,1,8
:Output(A,9-8L,"++++++++
:End
:Output(1,9-8L,"PLAYER
:Output(1,16-8L,L+1
:1→X
:1→Y
:DelVar G1→R
:Repeat R=11
:Repeat K=21
:For(A,0,expr(sub(Str2,R,1
:Output(X+AG,Y+Anot(G)+8L,sub("* ",2-[A](X+AG,Y+Anot(G)+8L),1
:End
:If Ans=31
:not(G→G
:min(8-Gexpr(sub(Str2,R,1)),max(1,X+sum(DeltaList(K={25,34→X
:min(8-not(G)expr(sub(Str2,R,1)),max(1,Y+sum(DeltaList(K={24,26→Y
:For(A,0,expr(sub(Str2,R,1
:Output(X+AG,Y+Anot(G)+8L,"*
:End
:Repeat Ans
:getKey→K
:End
:End
:DelVar HFor(A,0,expr(sub(Str2,R,1
:H+[A](X+AG,Y+Anot(G)+8L→H
:End
:If not(H
:Then
:For(A,0,expr(sub(Str2,R,1
:1→[A](X+AG,Y+Anot(G)+8L
:End
:If L
:T+1+expr(sub(Str2,R,1→T
:If not(L
:S+1+expr(sub(Str2,R,1→S
:R+1→R
:End
:End
:not(L→L
:End
:1→X
:Ans→Y
:randInt(0,1→L
:Lbl 1
:Repeat S=0 xor T=0
:ClrHome
:For(A,1,8
:Output(A,1+8L,"++++++++
:End
:Output(1,1+8L,"PLAYER
:Output(1,8+8L,L+1
:For(A,1,8
:For(B,9-8L,16-8L
:Output(A,B,sub(Str1,4-[A](A,B),1
:End
:End
:1→X
:9→Y
:Repeat K=21
:Output(X,Y-8L,sub(Str1,4-[A](X,Y-8L),1
:min(8,max(1,X+sum(DeltaList(K={25,34→X
:min(16,max(9,Y+sum(DeltaList(K={24,26→Y
:Output(X,Y-8L,"S
:Output(3,4+8L,sub("ABCDEFGH",X,1
:Output(3,5+8L,Y-8
:Repeat Ans
:getKey→K
:End
:End
:If 1<[A](X,Y-8L
:Then
:Output(5,1+8L,"TRY
:Output(6,4+8L,"AGAIN
:Pause
:Goto 1
:End
:If not([A](X,Y-8L
:Then
:Output(5,3+8L,"MISS
:3→[A](X,Y-8L
:not(L→L
:Pause
:Goto 1
:End
:If 1=[A](X,Y-8L
:Then
:Output(5,3+8L,"HIT!
:If L
:T-1→T
:If not(L
:S-1→S
:2→[A](X,Y-8L
:not(L→L
:Pause
:End
:End
:End
:DelVar [A]ClrHome
:not(L→L
:Output(4,5,"PLAYER
:Output(4,12,L+1
:Output(5,7,"WON!
Title: Re: Battle Ship
Post by: meishe91 on August 02, 2010, 06:21:38 pm
Thanks, I'll upload the source to see if anyone else can do anymore with it. I don't think there is though, but I'm very tired so I might have missed something.
Title: Re: Battle Ship
Post by: Builderboy on August 02, 2010, 06:26:31 pm
Making *any* game in a kilobyte or less is quite a task.  I myself had a pack of 1 kilobyte games in a folder somewhere but i dont have them anymore...
Title: Re: Battle Ship
Post by: meishe91 on August 02, 2010, 06:31:19 pm
just tried it out, and i am impressed
i rarely play anything in basic anymore, but this one's a keeper. props =D
EDIT: i glanced through the code really quickly and didnt see any obvious optimizations (cept mebbe where you used 1->x:1->y and then later 1->x:ans->y), but i like i said i havent messed with basic in a while and never on a screen this large, so...
DOUBLE EDIT: here's the code
Spoiler For To keep this post smaller:
Code: [Select]
:ClrHome
:"3221110000→Str2
:"MH  →Str1
:0identity(16→[A]
:DelVar TDelVar SDelVar LRepeat S=20 and T=20
:ClrHome
:For(A,1,8
:Output(A,9-8L,"++++++++
:End
:Output(1,9-8L,"PLAYER
:Output(1,16-8L,L+1
:1→X
:1→Y
:DelVar G1→R
:Repeat R=11
:Repeat K=21
:For(A,0,expr(sub(Str2,R,1
:Output(X+AG,Y+Anot(G)+8L,sub("* ",2-[A](X+AG,Y+Anot(G)+8L),1
:End
:If Ans=31
:not(G→G
:min(8-Gexpr(sub(Str2,R,1)),max(1,X+sum(DeltaList(K={25,34→X
:min(8-not(G)expr(sub(Str2,R,1)),max(1,Y+sum(DeltaList(K={24,26→Y
:For(A,0,expr(sub(Str2,R,1
:Output(X+AG,Y+Anot(G)+8L,"*
:End
:Repeat Ans
:getKey→K
:End
:End
:DelVar HFor(A,0,expr(sub(Str2,R,1
:H+[A](X+AG,Y+Anot(G)+8L→H
:End
:If not(H
:Then
:For(A,0,expr(sub(Str2,R,1
:1→[A](X+AG,Y+Anot(G)+8L
:End
:If L
:T+1+expr(sub(Str2,R,1→T
:If not(L
:S+1+expr(sub(Str2,R,1→S
:R+1→R
:End
:End
:not(L→L
:End
:1→X
:Ans→Y
:randInt(0,1→L
:Lbl 1
:Repeat S=0 xor T=0
:ClrHome
:For(A,1,8
:Output(A,1+8L,"++++++++
:End
:Output(1,1+8L,"PLAYER
:Output(1,8+8L,L+1
:For(A,1,8
:For(B,9-8L,16-8L
:Output(A,B,sub(Str1,4-[A](A,B),1
:End
:End
:1→X
:9→Y
:Repeat K=21
:Output(X,Y-8L,sub(Str1,4-[A](X,Y-8L),1
:min(8,max(1,X+sum(DeltaList(K={25,34→X
:min(16,max(9,Y+sum(DeltaList(K={24,26→Y
:Output(X,Y-8L,"S
:Output(3,4+8L,sub("ABCDEFGH",X,1
:Output(3,5+8L,Y-8
:Repeat Ans
:getKey→K
:End
:End
:If 1<[A](X,Y-8L
:Then
:Output(5,1+8L,"TRY
:Output(6,4+8L,"AGAIN
:Pause
:Goto 1
:End
:If not([A](X,Y-8L
:Then
:Output(5,3+8L,"MISS
:3→[A](X,Y-8L
:not(L→L
:Pause
:Goto 1
:End
:If 1=[A](X,Y-8L
:Then
:Output(5,3+8L,"HIT!
:If L
:T-1→T
:If not(L
:S-1→S
:2→[A](X,Y-8L
:not(L→L
:Pause
:End
:End
:End
:DelVar [A]ClrHome
:not(L→L
:Output(4,5,"PLAYER
:Output(4,12,L+1
:Output(5,7,"WON!

Ya, I thought I had something like that but that doesn't make to big of deal though because both are really fast as is and it won't reduce the size any. You can take the source down though, I got it up onto the original post :) Thanks though :D

Making *any* game in a kilobyte or less is quite a task.  I myself had a pack of 1 kilobyte games in a folder somewhere but i dont have them anymore...

Really? I didn't realize it was hard to keep games like this under a kilobyte. What kind of games did you have?
Title: Re: Battle Ship
Post by: Builderboy on August 02, 2010, 06:49:04 pm
There was a Snake game, Tetris, LunarLander, A defense game, among others
Title: Re: Battle Ship
Post by: meishe91 on August 02, 2010, 07:00:49 pm
Oh, nice. Sorry to hear they all got deleted.
Title: Re: Battle Ship
Post by: Builderboy on August 02, 2010, 07:12:50 pm
Yeah its fine, ill recreate them if i ever get bored :D
Title: Re: Battle Ship
Post by: meishe91 on August 02, 2010, 07:14:26 pm
Haha sounds good :P
Title: Re: Battle Ship
Post by: shmibs on August 02, 2010, 07:20:04 pm
i think i remember that lunar lander?(or was it a different one[regardless, fine precision games like that just dont work with ascii :P])
i'd love to see the others remade, though
Title: Re: Battle Ship
Post by: Raylin on August 02, 2010, 07:59:46 pm
It's actually quite a decent game.
I just played it. :)
Title: Re: Battle Ship
Post by: meishe91 on August 03, 2010, 04:43:42 am
Thank ya.
Title: Re: Battle Ship
Post by: ztrumpet on August 03, 2010, 01:32:37 pm
Nice job on the re-worked program. :)
Title: Re: Battle Ship
Post by: meishe91 on August 03, 2010, 01:52:01 pm
Thanks. I'm happier with this one because I got everything fixed and it's still smaller.
Title: Re: Battle Ship
Post by: Hot_Dog on August 03, 2010, 02:10:13 pm
How big is it now?  /me is impressed
Title: Re: Battle Ship
Post by: meishe91 on August 03, 2010, 02:57:14 pm
Ok. So I decided to completely do a rewrite of my Battle Ship program because I thought it was to big and just wasn't satisfied with it. I was also to lazy to just go back and rework the code to work. But anywho, to the program.

I did succeed in making this one smaller by about 62 bytes while still making it better than the previous version (it stands at 990 bytes). It should work perfectly now but if anyone discovers a bug please let me know.

[2ND] - It is the enter button.
[ALPHA] - When setting the maps this is what flips it between vertical and horizontal movement.
[ENTER] - Used to exit the Pause after turns.

This version fixes the previous bugs that I knew about. Like I said before if you find one just tell me and I'll try to fix it.

I can't think of much else to say so I'll let you guys to it. Have fun and enjoy.

Here is the source code in case anyone else can find optimizations. I'm very tired so there is a chance I missed something.

Spoiler For To Keep it Shorter:
Code: (Battle Ship Final) [Select]
ClrHome
"3221110000→Str2
"MH  →Str1
0identity(16→[A]
DelVar TDelVar SDelVar LRepeat S=20 and T=20
ClrHome
For(A,1,8
Output(A,9-8L,"++++++++
End
Output(1,9-8L,"PLAYER
Output(1,16-8L,L+1
1→X
1→Y
DelVar G1→R
Repeat R=11
Repeat K=21
For(A,0,expr(sub(Str2,R,1
Output(X+AG,Y+Anot(G)+8L,sub("* ",2-[A](X+AG,Y+Anot(G)+8L),1
End
If Ans=31
not(G→G
min(8-Gexpr(sub(Str2,R,1)),max(1,X+sum(DeltaList(K={25,34→X
min(8-not(G)expr(sub(Str2,R,1)),max(1,Y+sum(DeltaList(K={24,26→Y
For(A,0,expr(sub(Str2,R,1
Output(X+AG,Y+Anot(G)+8L,"*
End
Repeat Ans
getKey→K
End
End
DelVar HFor(A,0,expr(sub(Str2,R,1
H+[A](X+AG,Y+Anot(G)+8L→H
End
If not(H
Then
For(A,0,expr(sub(Str2,R,1
1→[A](X+AG,Y+Anot(G)+8L
End
If L
T+1+expr(sub(Str2,R,1→T
If not(L
S+1+expr(sub(Str2,R,1→S
R+1→R
End
End
not(L→L
End
1→X
Ans→Y
randInt(0,1→L
Lbl 1
Repeat S=0 xor T=0
ClrHome
For(A,1,8
Output(A,1+8L,"++++++++
End
Output(1,1+8L,"PLAYER
Output(1,8+8L,L+1
For(A,1,8
For(B,9-8L,16-8L
Output(A,B,sub(Str1,4-[A](A,B),1
End
End
1→X
9→Y
Repeat K=21
Output(X,Y-8L,sub(Str1,4-[A](X,Y-8L),1
min(8,max(1,X+sum(DeltaList(K={25,34→X
min(16,max(9,Y+sum(DeltaList(K={24,26→Y
Output(X,Y-8L,"S
Output(3,4+8L,sub("ABCDEFGH",X,1
Output(3,5+8L,Y-8
Repeat Ans
getKey→K
End
End
If 1<[A](X,Y-8L
Then
Output(5,1+8L,"TRY
Output(6,4+8L,"AGAIN
Pause
Goto 1
End
If not([A](X,Y-8L
Then
Output(5,3+8L,"MISS
3→[A](X,Y-8L
not(L→L
Pause
Goto 1
End
If 1=[A](X,Y-8L
Then
Output(5,3+8L,"HIT!
If L
T-1→T
If not(L
S-1→S
2→[A](X,Y-8L
not(L→L
Pause
End
End
End
DelVar [A]ClrHome
not(L→L
Output(4,5,"PLAYER
Output(4,12,L+1
Output(5,7,"WON!

And thanks.
Title: Re: Battle Ship
Post by: DJ Omnimaga on August 04, 2010, 08:08:43 pm
wow nice update! Pretty small too. I agree it's hard to keep a lot of games under 1 KB. I myself often had an hard time doing it with anything other than tunnel
Title: Re: Battle Ship
Post by: ztrumpet on August 05, 2010, 10:33:17 am
wow nice update! Pretty small too. I agree it's hard to keep a lot of games under 1 KB. I myself often had an hard time doing it with anything other than tunnel
Wasn't there the one where...
* Netham45 runs!
...yeah... ;D
Title: Re: Battle Ship
Post by: DJ Omnimaga on August 06, 2010, 09:43:46 pm
Oh right, that one...