Jump to content

Photo

is this viable / possible on the TI99/4A? using XB


14 replies to this topic

#1 1980gamer OFFLINE  

1980gamer

    Dragonstomper

  • 941 posts
  • Location:Charlton, MA

Posted Sat Sep 8, 2018 3:04 AM

I need to write a recursive function  well subroutine that will scan the play field for adjacent matching blocks.

 

5x5 example:

 

10011

11010

01100

00100

1111     <--  if a 1 is dropped here

 

the X's would be removed data

 

x0011

xx010

0xx00

00x00

xxxxx

 

Leaving:

 

0011

010

000

0000

 

Dropping a zero on any of the bottom 3 lines would leave us

 

11

1

 

Think along the line of Same Game.  In fact, I was thinking of trying to do same game!  But this is for something else.

 

I would be grateful any feedback or expedience you may have.

 

 

 

 



#2 RXB OFFLINE  

RXB

    River Patroller

  • 3,303 posts
  • Location:Vancouver, Washington, USA

Posted Sat Sep 8, 2018 3:18 AM

Is this XB?



#3 1980gamer OFFLINE  

1980gamer

    Dragonstomper

  • Topic Starter
  • 941 posts
  • Location:Charlton, MA

Posted Sat Sep 8, 2018 5:45 AM

Ideally it would be done in XB.

 

However, it may not be possible.  Or if possible, maybe to slow to be viable?

 

If a "plug-in" could be used, I would do that, if XB is not possible.  I may need to brute force this, but that would certainly be slow and larger than I want.


Edited by 1980gamer, Sat Sep 8, 2018 5:45 AM.


#4 Asmusr OFFLINE  

Asmusr

    River Patroller

  • 2,870 posts
  • Location:Denmark

Posted Sat Sep 8, 2018 9:41 AM

Instead of a recursive function you could use a stack to keep track of which block to check next.



#5 1980gamer OFFLINE  

1980gamer

    Dragonstomper

  • Topic Starter
  • 941 posts
  • Location:Charlton, MA

Posted Sat Sep 8, 2018 7:19 PM

Hi Asmusr,  A stack?

 

I don't know what you are saying?  Maybe this is what I call brute force?

 

My play field will be at the most 10x9 -1  I was first thinking of storing row and column data in an array were Source Char matched the char to the left and keep going left until it did not match.

Then, Match up 1.  If it matched, then go left until no match, then go right until no match.  Now, do I go up a row, or do I go left or right if a match exists, then go up.  then look left right over and over...

This runs away quickly.  Thus, recursive seems like the way to do this.....?

 

But, I have seen the magic you have created here.  So, can you explain use a stack for me?  Note.  I am a very procedural thinker.  I write TSQL all day..



#6 Asmusr OFFLINE  

Asmusr

    River Patroller

  • 2,870 posts
  • Location:Denmark

Posted Sun Sep 9, 2018 7:19 AM

A stack is a list or array with two main operations: push to place a value on top of the stack and pop to get and remove the top value.

 

It would take me far too long time to try to write this in BASIC, so here is some pseudo Java-like code to try to explain the difference between using a recursive function and a stack. To keep it short I'm assuming you can push two values onto the stack in one operation: stack.push(x,y).

Recursive:

check(x, y, value) {
	if (map(x,y)==value) {
	    map(x,y)='x'
	    check(x-1,y,value)
	    check(x,y+1,value)
	    check(x,y-1,value)
	}
}

Using a stack:

stack.push(x, y)
while (stack.isNotEmpty()) {
	y = stack.pop()
        x = stack.pop()
	if (map(x,y)==value) {
		map(x,y)='x'
		stack.push(x-1,y)
		stack.push(x,y+1)
		stack.push(x,y-1)
	}
}



#7 1980gamer OFFLINE  

1980gamer

    Dragonstomper

  • Topic Starter
  • 941 posts
  • Location:Charlton, MA

Posted Sun Sep 9, 2018 8:13 AM

Thank you for the example!

 

I will try to convert this to xb   I think I can do this. 

 

Don't you wish TI had do while   I use for next with early exit logic.   I used to roll my own, but I have been using for next lately and it is easier.



#8 RXB OFFLINE  

RXB

    River Patroller

  • 3,303 posts
  • Location:Vancouver, Washington, USA

Posted Mon Sep 10, 2018 1:44 AM

Thank you for the example!

 

I will try to convert this to xb   I think I can do this. 

 

Don't you wish TI had do while   I use for next with early exit logic.   I used to roll my own, but I have been using for next lately and it is easier.

Hmmm DO WHILE is just:

If X=SOMETHING THEN SUBROUTINE

 

You could even make it a SUB routine CALL DOWHILE(x)



#9 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,726 posts
  • Location:Silver Run, Maryland

Posted Mon Sep 10, 2018 6:30 AM

Hmmm DO WHILE is just:

If X=SOMETHING THEN SUBROUTINE

 

You could even make it a SUB routine CALL DOWHILE(x)

 

That is not how Do..While works, Rich.  The following is how one might implement Asmusr’s while():

100 REM ...part of program that manipulates X
    .
    .
    .
500 IF X=0 THEN 600         ! WHILE condition
510 REM ...WHILE true part
    .
    .
    .
590 GOTO 500
600 REM ...remainder of program (WHILE false part)

...lee



#10 RXB OFFLINE  

RXB

    River Patroller

  • 3,303 posts
  • Location:Vancouver, Washington, USA

Posted Mon Sep 10, 2018 1:41 PM

How is mine any different you just added more lines?

 

I just did not add in a GOTO that IF X=SOMETHING THEN SUBROUTINE

 

40 IF X=0 THEN CALL DOWHILE :: GOTO 40 ELSE 50

50 ....

 

 

1000 SUB DOWHILE(X) 

 

 

1010 SUBEND 

 

What exactly did I get wrong?

 

Also you could drop the ELSE 50 and would still work.

 

Anyway why do we need DO WHILE when we already have exactly what it does?

It is like putting a cup holder on your your cup holder..not really needed.


Edited by RXB, Mon Sep 10, 2018 1:47 PM.


#11 Ksarul ONLINE  

Ksarul

    River Patroller

  • 4,741 posts

Posted Yesterday, 7:57 PM

The Geneve does have DO WHILE in ABASIC. . .



#12 1980gamer OFFLINE  

1980gamer

    Dragonstomper

  • Topic Starter
  • 941 posts
  • Location:Charlton, MA

Posted Yesterday, 8:38 PM

I wanted one of those... Or the TI99/8A



#13 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 703 posts
  • Location:The Great White North

Posted Yesterday, 9:41 PM

 

Anyway why do we need DO WHILE when we already have exactly what it does?

It is like putting a cup holder on your your cup holder..not really needed.

 

You are correct. You don't need it. 9900 Assembly language does not have structured loops...   well...  except in Forth assembler. :-)

 

But all of these things came out of the development of structured programming.  It was felt by the experts like Dijkstra and Wirth that structuring things would get "spaghetti code" under control.

Maintaining commercial programs is a bigger expense than writing the code. It goes on for years.

Code that jumps all over the place gets hard to understand from the text of the program for the maintainer and is harder to modify.

 

So the structures that were common made you keep your loops localized.

FOR NEXT is one such structured loop in BASIC but you don't need it. 

 

I remember that structured programming ticked off some people back in the day. They saw it as inefficient.

 

Dijkstra was clear on what he thought:

"It is practically impossible to teach good programming to students that have had a prior exposure to BASIC:

 as potential programmers they are mentally mutilated beyond hope of regeneration"

 

He was apparently rather opinionated.  ;-)  



#14 RXB OFFLINE  

RXB

    River Patroller

  • 3,303 posts
  • Location:Vancouver, Washington, USA

Posted Yesterday, 10:06 PM

People do not think like Forth (Stack thinking) as you have to force yourself to thinking like a Computer stack, it does not come naturally.

Quantum computers do behave more like how our minds work.

 

Not Binary but multiple states. 



#15 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 703 posts
  • Location:The Great White North

Posted Yesterday, 10:36 PM

People do not think like Forth (Stack thinking) as you have to force yourself to thinking like a Computer stack, it does not come naturally.

Quantum computers do behave more like how our minds work.

 

Not Binary but multiple states. 

 

True. Stack machines take some practice to get use to.

 

I was actually thinking about the dawn of structured programming with languages like Algol68, Pascal, and C.

 

Forth used these same ideas probably (I don't know for certain) because it comes from the late 60s/early 70s time frame like these other old languages.


  • RXB likes this




1 user(s) are browsing this forum

1 members, 0 guests, 0 anonymous users