Knuckle Cracker

Creeper World 3 => Upcoming Release Chatter => Topic started by: Tiuipuv on December 24, 2012, 04:44:06 PM

Title: CRPL Ideas/Questions
Post by: Tiuipuv on December 24, 2012, 04:44:06 PM
I love the new CRPL, and can't wait to get started. So, I'm starting now ;D. As a language, I found it unusual to get used to, but very efficient once I got more accustomed to programming backwards. Unfortunately, I don't know a lot about it. I took one of my ideas and put it into code, and have *some* things to ask about it.

I attempted to create a Mobile Creeper Launcher. The idea behind it is to move to the deepest creeper on the map, and pick it up, put it into a spore that targets the shallowest/no creeper area on the the map. Whatever amount it picks up, the spore drops on impact. The more creeper it picks up, the faster the spore travels. Of course, all the particular numbers would be subject to balancing through testing. Here is what I have:


Mobile Creeper Launcher


#1
GetQueuedMoveCount eq0 if

#2
CurrentCoords GetShallowestCreeperCoords

#3
0

#4
CurrentY 3 add CurrentY 2 sub do

CurrentX 3 add CurrentX 2 sub do

#5
I J GetCreeperCount add

I J 0 SetCreeper

loop

loop

#6
20 div Duplicate 20 mul CreateSpore

#7
GetDeepestCreeperCoords 1 QueueMove

endif


#1
GetQueuedMoveCount eq0 if

Does eq0 turn the number on top of the stack into a true/false value (true if equals 0, false otherwise)? Then the if won't do anything unless the top of the stack is a true? That would make sense to me.

#2
CurrentCoords GetShallowestCreeperCoords

GetShallowestCreeperCoords is what I have inserted; there would be some complicated code here searching the map for the area with the lowest/no creeper, defining ties and such. It would be nice to just make things up like I did here :).

There was an interesting problem with stack order here. These sets of coords are later used for a spore (#6). This should work as long as I keep the stack under control, right?

#3
0

This 0 is because the do loop will be adding up a total count, and I think this would provide a number for it to add to. This could be subject to balancing in game, a nonzero number would provide a minimum spore amount. A negative number has interesting effects...

#4
CurrentY 3 add CurrentY 2 sub do

My entire exposure to do loops is what virgil showed in the video, so I probably have it all wrong. How could this be used correctly?

This could be rendered unnecessary with a clever command pre-built. Something like SetCreeperInRange and GetCreeperCountInRange.

Why does Virgil's add 2 and subtract 1? Does it have something to do with how the do loop handles the center square?

#5
I J GetCreeperCount add

In the Video I noticed a strange I J, those seem to be taking information out of the do loop, but I don't understand the do loop to begin with. Why I and J, and how do their values get assigned?

I haven't noticed the command GetCreeperCount, but I'm assuming it would be possible to find the amount of creeper in a single cell.

Here is where I try to make a total of how much creeper was in the 5 by 5 cell area in a single number, and put that on top of the stack. I also try to set the creeper in the 5 by 5 area to 0. Again my lack of experience with do loops leaves me stuck.

#6
20 div Duplicate 20 mul CreateSpore

Here I use another unseen, but very necessary command. Where I put "Duplicate" I would take the current value from the top of the stack, and put it on top of the stack above itself. I don't see a workaround here, there must be some sort of command for it.

"div" stands for divide, and "mul" stands for multiply.

Here is where I create a spore, without providing enough information "directly" beforehand. I assume that it would be possible to retrieve older values from the stack in just the same way, in this case from #2.

#7
GetDeepestCreeperCoords 1 QueueMove

Again with the search for creeper levels. It would probably be possible to use the previous one (#2) to find this as well, for performance reasons.



So there's clearly a lot I don't get yet, and even still I think I get it better than the general population. I would love to see what some of you smart people are thinking put into code (even if we don't have much to work with yet). It should help all of us who want to use this infinitely malleable new feature :).
Title: Re: CRPL Ideas/Questions
Post by: J on December 24, 2012, 05:11:20 PM
Sorry, but I don't know if and how much I can reveal from beta...
But there are some things you already seem to know from the vid, a few improvements:
Duplicate -> dup
I J GetCreeperCount -> I J GetCreeper
#3 is completely unnecessary
div needs 2 values (10 2 div -> 10/2=)
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on December 24, 2012, 05:56:32 PM
What we cannot do at this time is to discuss the specific set of CRPL commands or the capabilities of units using it. Those things are subject to change and to beta-test validation.

We can help you with syntax validation and with questions on how the language (Reverse Polish Notation) works in specific circumstances.

Also, refer to my PSA thread on this board to a link where you can play with a similar language to test how logic and stack operations function.

Quote from: Tiuipuv on December 24, 2012, 04:44:06 PM

#1
GetQueuedMoveCount eq0 if

Does eq0 turn the number on top of the stack into a true/false value (true if equals 0, false otherwise)? Then the if won't do anything unless the top of the stack is a true? That would make sense to me.

Yes, assuming that there is a command "GetQueuedMoveCount" then that will be on the stack as an integer. If it is 0, then the equation would evaluate to True.

This is how we would write it in stack notation:

0 -- 1


The zero queued moves will result in a True condition.

Quote
#2
CurrentCoords GetShallowestCreeperCoords

GetShallowestCreeperCoords is what I have inserted; there would be some complicated code here searching the map for the area with the lowest/no creeper, defining ties and such. It would be nice to just make things up like I did here :).

There was an interesting problem with stack order here. These sets of coords are later used for a spore (#6). This should work as long as I keep the stack under control, right?

Well, I see a logic problem here. For CurrentCoords you will have a single co-ordinate pair. THat would be the coordinates where the unit is located. That will only return one value - the depth of creeper at that location.

For you to do what you want, you'd have to devise a different algorithm. I'll leave that to you as a learning exercise. :)

Quote
#3
0

This 0 is because the do loop will be adding up a total count, and I think this would provide a number for it to add to. This could be subject to balancing in game, a nonzero number would provide a minimum spore amount. A negative number has interesting effects...

Not sure what you mean here.  Addition works as follows:

4 5 add

in stack notation:


4 5 -- 9


Quote

#4
CurrentY 3 add CurrentY 2 sub do

My entire exposure to do loops is what virgil showed in the video, so I probably have it all wrong. How could this be used correctly?

This could be rendered unnecessary with a clever command pre-built. Something like SetCreeperInRange and GetCreeperCountInRange.

Why does Virgil's add 2 and subtract 1? Does it have something to do with how the do loop handles the center square?

Virgil's code probably process a square of 9 cells centered around the current coordinates. Thus +1 and _1 from where the current {x,y} coordinate pair is located.

for your code, let's analyze it in stack notation again:

CurrentY 3 add CurrentY 2 sub do

Assume CurrentY is 40 and CurrentX is 36



40 3 -add- 43 40 2 -sub- 43 38 -do-


So now we can deduce that your do-loop will iterate over the values from 38 to 43.

Quote
#5
I J GetCreeperCount add

In the Video I noticed a strange I J, those seem to be taking information out of the do loop, but I don't understand the do loop to begin with. Why I and J, and how do their values get assigned?

Each do-loop has an internal index that gets adjusted from the starting index number (see above) to the limit of the do loop.  For the sake of this, that is what the I, J (and K) values are.  Simply the index for each nested loop.


Quote

#6
20 div Duplicate 20 mul CreateSpore

Here I use another unseen, but very necessary command. Where I put "Duplicate" I would take the current value from the top of the stack, and put it on top of the stack above itself. I don't see a workaround here, there must be some sort of command for it.

"div" stands for divide, and "mul" stands for multiply.

Here is where I create a spore, without providing enough information "directly" beforehand. I assume that it would be possible to retrieve older values from the stack in just the same way, in this case from #2.

You are absolutely right. RPL does have a "dup" and "dup2" operation to duplicate one or two stack items.

As for your code, it would fail from what I can see, since both division and multiplication requires two operands on the stack.

Here is how to get the square of 5 in a RPL.

5 dup *[/quote]

Stack notation"[code] 5-dup- 5 5 -*- 25



Hope that guides you a little on using RPL (and eventually CRPL. :)[/code]
Title: Re: CRPL Ideas/Questions
Post by: lurkily on December 24, 2012, 06:35:41 PM
Here's an example of RPL in a vertical table.  One way to think of "20 2 div 5 mult" it is that it uses the operators to 'collapse' the values on the bottom of the stack.  It creates a stack of 2 over 20, and with Div, collapses them to 10.  Then it has the two operands necessary for the multiplication.

Most people used to modern language are probably going to have trouble thinking of their code as a stack of values, so some visualization can help.  For instance, 20 2 div 5 mult:
step 1 step 2step 3
mult
5
divmult
25
201050

It can also help to duplicate your code in a comment, and there, section it out to verify that you have enough operands for each item.  I used a personal notation kind of like this when first getting my shoes wet with CRPL (about a week ago) and still find that it helps when using long, complex strings.

# ((20 2 div) 5 mult)
20 2 div 5 mult
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on December 24, 2012, 06:46:52 PM
Quote from: lurkily on December 24, 2012, 06:35:41 PM
Here's an example of RPL in a vertical table.  One way to think of "2 20 div 5 mult" it is that it uses the operators to 'collapse' the values on the bottom of the stack.  It creates a stack of 2 over 20, and with Div, collapses them to 10.  Then it has the two operands necessary for the multiplication.


There's a problem with your example.


2 divided by 20 yields 0 as integer


Test it here: http://forthfreak.net/jsforth80x25.html
Title: Re: CRPL Ideas/Questions
Post by: Tiuipuv on December 24, 2012, 08:13:53 PM

0

CurrentY 3 add CurrentY 2 sub do

CurrentX 3 add CurrentX 2 sub do

I J GetCreeperCount add

I J 0 SetCreeper

loop

loop


The idea was to end up with a number on top of the stack, equal to the amount of creeper that had been in the area. Both J and Grauniad said that this doesn't happen. How could you achieve the result of a single number on the stack (the total amount of creeper) once the loop is done?

Quote from: Grauniad on December 24, 2012, 05:56:32 PM
Quote
#2
CurrentCoords GetShallowestCreeperCoords

GetShallowestCreeperCoords is what I have inserted; there would be some complicated code here searching the map for the area with the lowest/no creeper, defining ties and such. It would be nice to just make things up like I did here :).

There was an interesting problem with stack order here. These sets of coords are later used for a spore (#6). This should work as long as I keep the stack under control, right?

Well, I see a logic problem here. For CurrentCoords you will have a single co-ordinate pair. THat would be the coordinates where the unit is located. That will only return one value - the depth of creeper at that location.

For you to do what you want, you'd have to devise a different algorithm. I'll leave that to you as a learning exercise. :)

Where I put GetShallowestCreeperCoords, I'm not using anything previously on the stack. What it is supposed to mean is that it finds the X and Y coordinates on the map where the Creeper is shallowest. Perhaps I should have put FindShallowestCreeperCoords instead. Unless I have something completely misunderstood...

Quote from: Grauniad on December 24, 2012, 06:46:52 PM
Quote from: lurkily on December 24, 2012, 06:35:41 PM
Here's an example of RPL in a vertical table.  One way to think of "2 20 div 5 mult" it is that it uses the operators to 'collapse' the values on the bottom of the stack.  It creates a stack of 2 over 20, and with Div, collapses them to 10.  Then it has the two operands necessary for the multiplication.


There's a problem with your example.


2 divided by 20 yields 0 as integer


Test it here: http://forthfreak.net/jsforth80x25.html

So all numbers in the stack will be integers? Good. As much as it may get in the way, it will prove easier on my brain I think. Is that by rounding or flooring? But wait, in Virgil's picture he has a .8...

I do believe that lurkily meant 20 2 div, because that would match the table and the math.
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on December 24, 2012, 09:02:33 PM
Quote from: Tiuipuv on December 24, 2012, 08:13:53 PM
The idea was to end up with a number on top of the stack, equal to the amount of creeper that had been in the area. Both J and Grauniad said that this doesn't happen. How could you achieve the result of a single number on the stack (the total amount of creeper) once the loop is done?

Suppose we want to calculate the amount of creeper in a 3 x 3 cell around a tower at coordinates {x,y: 30,15}. Then, using this pseudo-code we can do it. This is more an example of the use of RPL than of CRPL, since you cannot rely that any command I use in the pseudo-code will eventually be implemented in CRPL.


#define a variable to hold the amount of creeper and set it to zero.
0->AllCreeper
# stack notation for above: 0 --

#set center X: Stack 30 --
30 ->MyX

#set center Y: Stack 15 --
15 ->MyY

#Calculate low and high X: There is a more elegant way, but the code gets increasingly complex.
# So I'm doing it in steps and hopefully you can follow.

<-MyX 1 add dup 2 sub ->LowX ->HighX
#stack notation: 30 1 -add- 31 -dup- 31 31 -sub- 31 29 ->LowX=29, HighX=31

#Outer loop for x
<-HighX <-HighY do

   #same for Y:
      <-MyY 1 add dup 2 sub ->LowY ->HighY
      #stack notation: 15 1 -add- 16 -dup- 16 16 -sub-16 14 ->lowY=14, HighY=16

       #inner loop for y
       <-HighX <-HighY do
             
            # the loop indexes are I for the y-coordinate (inner loop) and J for the outer (X) loop
             J I GetCreeper <-AllCreeper add ->AllCreeper
             #stack notation: (first iteration) 29 14 -GetCreeper- (assume creeper level 5) 5 0 -add- 5 ->
       
        Loop #inner loop
    Loop #outer loop

#we'll iterate over the loops and add creeper to the AllCreeper variable


Pretty sure I might have made a mistake, it's hard to be accurate without the aid of a compiler. :)

the condensed version of the loops (as Virgil probably used them) are:


<-MyX 1 add dup 2 sub do  #stack notation:30 1 -add- 31 -dup- 31 31 -sub- 31 29 -do-
  <-<-MyY 1 add dup 2 sub do #stack notation: 15 1 -add- 16 -dup- 16 16 -sub-16 14 -do-
      #code to execute goes here
  loop
loop
/code]

I hope this helps you to wrap your head around RPL code writing and design....
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on December 24, 2012, 09:08:34 PM
Quote from: Tiuipuv on December 24, 2012, 08:13:53 PM

So all numbers in the stack will be integers? Good. As much as it may get in the way, it will prove easier on my brain I think. Is that by rounding or flooring? But wait, in Virgil's picture he has a .8...


If you do integer division, then the result will be integer (with modulus support).  There is support for floating point numbers and the core will convert as needed or you can explicitly convert.
Title: Re: CRPL Ideas/Questions
Post by: florrat on December 24, 2012, 09:13:14 PM
Quote from: Grauniad on December 24, 2012, 05:56:32 PM
40 3 -add- 43 40 2 -sub- 43 38 -do-

So now we can deduce that your do-loop will iterate over the values from 38 to 43.
Excluding 43, right?




As far as I understand the (C)RPL (which is not very "far"), the code of Tiuipuv is correct and does what he wants (if the functions GetShallowestCreeperCoords, GetDeepestCreeperCoords and GetCreeperCount are (somehow) defined, and he replaces Duplicate by dup).

In the first iteration on the do loop, the stack is
<4 numbers from CurrentCoords GetShallowestCreeperCoords> 0
and then the command
I J GetCreeperCount add
first looks what the amount of creeper is on (I,J), say x, and then adds it to the 0 on the stack, so the stack would become
<4 numbers from CurrentCoords GetShallowestCreeperCoords> x
and the next iteration the same happens, it adds the amount of creeper on (I+1,J) to the last number on the stack (x). After all 25 iterations, the last number of the stack represents the total value of creeper in these 25 cells (before it was removed), and then he uses this value to make the spore.

This sounds perfectly legal to me.

Quote from: Tiuipuv on December 24, 2012, 04:44:06 PMThe more creeper it picks up, the faster the spore travels.
Wait, the speed of the spore is independent of the amount of creeper it picked up, right? Since CreateSpore does not have "spore speed" as argument in the version of the video.




EDIT: There will probably also be commands to interchange to elements on the stack, right? How do these work in stack bases languages? For example suppose that my stack is X Y Z and I want it to be (X+1) Y Z Then I first have to move X to the top of the stack, then add 1 to it, and then move it back, right? How can you achieve this?
Title: Re: CRPL Ideas/Questions
Post by: lurkily on December 24, 2012, 09:21:15 PM
Yes, "20 2 div 5 mult" was what I intended - corrected.  I got it right three out of four times, at least.

Anyway, the point of the exercise is to illustrate how the code 'thinks'.  A lot of modern languages are somewhat analogous to english in that you can toss in a few extra words here and there and it makes sense - the thought processes involved in the english language can guide you in structuring the code you write.  Because that isn't the case here, I think it's important to be able to visualize the processes the code goes through as it reduces itself to a result.

Quote from: Tiuipuv on December 24, 2012, 08:13:53 PMCurrentY 3 add CurrentY 2 sub do

CurrentX 3 add CurrentX 2 sub do

I J GetCreeperCount add

I J 0 SetCreeper

loop

loop


The idea was to end up with a number on top of the stack, equal to the amount of creeper that had been in the area. Both J and Grauniad said that this doesn't happen. How could you achieve the result of a single number on the stack (the total amount of creeper) once the loop is done?

0 ->CreeperTotal

#Repeat 5 times, for a height of 5
CurrentY 3 add CurrentY 2 sub do

#Repeat 5 times, for a width of 5
CurrentX 3 add CurrentX 2 sub do

#Get the creeper in this cell, and add it to a total
I J GetCreeperCount <-CreeperTotal add ->CreeperTotal

loop

loop
Does this look what you're trying to do?   You appear to be trying to count the total creeper in all cells in a 5x5 area, yes?
Title: Re: CRPL Ideas/Questions
Post by: Tiuipuv on December 24, 2012, 09:54:09 PM
Grauniad:
Thank you! You clearly have a strong understanding of how this works right from the ground up.

Florrat:
Thank you for explaining what I was trying to say. I couldn't get all the steps so completely.

I said speed...oops. Health belongs there, but I suppose it works just the same anyway.

Interchanging elements of the stack would be very convenient, maybe if the situation was right it could be necessary.

Lurkily:
Yes, precisely.
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on December 24, 2012, 10:33:17 PM
Quote from: florrat on December 24, 2012, 09:13:14 PM
Excluding 43, right?

I probably said it very badly.

The loop construct (here is a good reference (http://www.forth.com/starting-forth/sf6/sf6.html)) has the syntax:

limit index DO ... LOOP

The description is:
Quote
In Forth, you do this by specifying a beginning number and an ending number (in reverse order) before the word DO. Then you put the words which you want to have repeated between the words DO and LOOP. For example

  : TEST   10 0 DO  CR ." Hello "  LOOP ;

This will print the word "Hello" 10 times.

So yes, I think I made a mistake in specifying the bounds of the loop.

Edit: Fixed reference.
Title: Re: CRPL Ideas/Questions
Post by: florrat on December 26, 2012, 01:43:02 PM
@Grauniad: Could you please fix the link to the good reference, I'd like to see it.

@lurkily: That's what he's indeed trying to do, but - I think - also doing. I still think his code should work, unless the stack is emptied every line or so (which seems rather strange)... I'd like to hear more about your reasons why his code will (probably) not work, because you say stack he tries to use the add- and div-command while the stack has only 1 number in it, but that's not true, unless I'm missing something

I'd also like to hear (or read in a good reference :) ) how interchanging numbers on the stack works.
Title: Re: CRPL Ideas/Questions
Post by: lurkily on December 26, 2012, 02:40:16 PM
The line I referred to was:

20 div Duplicate 20 mul CreateSpore

Div only has a single operand, '20'.

Also,
I J GetCreeperCount add
gives 'add' only a single operand.

EDIT:By interchanging numbers, are you referring to the use of 'swap'?
Title: Re: CRPL Ideas/Questions
Post by: florrat on December 26, 2012, 06:40:06 PM
In this post I assume the stack is not emptied every newline. If this is false, this whole message contains rubbish. And maybe I'm wrong in how stack-based languages work... In that case, sorry for my wrong statements below. If it makes you feel better: please read every sentence as if it started with "If my understanding of stack bases languages is correct ..."


@lurkily: I agree that the following two codes are invalid by themselves. 20 div dup 20 mul CreateSporeI J GetCreeperCount add

But, suppose these two lines are executed when there are already numbers on the stack (before the line is executed), then these lines can be executed correctly: they will use the last value which was on the stack to evaluate the div and the add (and use up even more numbers from the stack when resolving CreateSpore).

For example the first piece of code. Suppose, before this code gets executed the stack contains 5 numbers, and to simplify things, lets assume the last number is 200. So the stack is A B C D 200 for some numbers A, B, C and D.
After 20 is evaluated, the stack contains A B C D 200 20;
After div is evaluated, we remove the 200 and the 20 from the stack, and compute 200/20=10, so the stack contains A B C D 10;
After dup is evaluated, the last element of the stack is duplicated, so we get A B C D 10 10;
After 20 is evaluated, we get A B C D 10 10 20;
After mul is evaluated, we get A B C D 10 200 (10 and 20 are replaced by 200);
Now CreateSpore removes all these numbers from the stacks and creates a spore with the right properties.

And this is exactly what Tiuipuv code is doing.


Or maybe even simpler: when my code is
0

dup


If you read the line "dup" by itself, it is an invalid use. But in the code as above, the dup will just duplicate the 0 which was on the stack from two lines above (resulting in 0 0 as stack).


About "swap": probably, I don't know that command; could you describe what it does (probably easiest with an example).
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on December 26, 2012, 06:54:28 PM
Swap:

  4 5 swap

Stack notation:

4 5 -- 5 4
Title: Re: CRPL Ideas/Questions
Post by: florrat on December 26, 2012, 08:03:02 PM
Looks good, but rather limited. Are there ways to swap elements further down the stack?
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on December 26, 2012, 08:08:55 PM
Quote from: florrat on December 26, 2012, 08:03:02 PM
Looks good, but rather limited. Are there ways to swap elements further down the stack?

http://astro.pas.rochester.edu/legacy/Forth/stack.html
Title: Re: CRPL Ideas/Questions
Post by: asmussen on December 26, 2012, 08:10:02 PM
Quote from: florrat on December 26, 2012, 08:03:02 PM
Looks good, but rather limited. Are there ways to swap elements further down the stack?

In any stack oriented language, by definition you are pretty much limited to only being able to manipulate the data at the top of the stack. It does take some getting used to when you first learn to think that way, but there are definite advantages to it when it comes to actually implementing the language.
Title: Re: CRPL Ideas/Questions
Post by: ShadowDragon7015 on December 27, 2012, 11:54:43 AM
is there a way to make the CRPL tower go back and forth along a line like it is patrolling and then have it fire spores a certain distance forward towards the command center? I mostly want to know about the firing the spores in one direction.
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on December 27, 2012, 12:14:45 PM
Quote from: ShadowDragon7015 on December 27, 2012, 11:54:43 AM
is there a way to make the CRPL tower go back and forth along a line like it is patrolling and then have it fire spores a certain distance forward towards the command center? I mostly want to know about the firing the spores in one direction.
That all seems possible.  Movement commands and firing spores at specific targets are included. So is the ability to obtain the location of a CN (I think).
Title: Re: CRPL Ideas/Questions
Post by: asmussen on December 27, 2012, 12:57:35 PM
Is the CRPL tower an enemy unit that must be destroyed for map victory (On maps where destroying the enemy is the objective)? Is it possible to somehow setup a CRPL tower with a script that will run for the entire time the map is being played, without being subject to being destroyed by player activity?
Title: Re: CRPL Ideas/Questions
Post by: lurkily on December 27, 2012, 01:11:01 PM
Virgil in his demo queued random coordinated for his movements - if you simply queued movements between two mapper-entered coords instead, you should get the behavior you describe.

As to whether it must be destroyed, there's no word on that yet, but I am hoping, personally, that this decision will rest in the mapper's hands.
Title: Re: CRPL Ideas/Questions
Post by: hoodwink on December 27, 2012, 01:59:45 PM
Quote from: asmussen on December 27, 2012, 12:57:35 PM
Is the CRPL tower an enemy unit that must be destroyed for map victory (On maps where destroying the enemy is the objective)? Is it possible to somehow setup a CRPL tower with a script that will run for the entire time the map is being played, without being subject to being destroyed by player activity?
I remember somebody mentioning somewhere that it will be possible to set up a 'ghost' tower that doesn't have a physical presence on the map (or similar), but still runs a script. That way, a script will not be subject to being nullified, since it's tower is not on the list of things to be obliterated.
Title: Re: CRPL Ideas/Questions
Post by: lurkily on December 27, 2012, 05:34:32 PM
If a tower can change its image (in particular, change it to 'none') and remove itself from targeting by player units such as nullifiers, that will be true.

All of these things are things that I think of as necessary to get the best bang for the buck with this tower, but so far V has said nothing definitive on the subject.
Title: Re: CRPL Ideas/Questions
Post by: Tiuipuv on December 28, 2012, 03:16:59 PM
I didn't want to leave something in my code that didn't mean anything. So, I have created code to define GetDeepestCreeperCoords. Here it is, without any notations:

1 1 1 1 GetCreeper SetVar0 GetVar0

600 1 do
400 1 do
I J GetCreeper GetVar0 gt if
drop drop I J I J GetCreeper SetVar0
endif
loop
loop


And, as usual, it brought my attention to lots of little points.

#1
The stack is not cleared after every line, right? As long as it isn't cleared, then it shouldn't matter if things get put in the same line or not. For instance, creating creeper at current coords looks like this:

CurrentCoords SetCreeper

But it could also look like this:

CurrentCoords
SetCreeper


So in theory, all of my code could go on one line, or only one word per line if I wished. Is that correct?

#2
There also must be some command for removing an item from the stack (I think), and I found one listed as "drop" from Grauniad's link http://astro.pas.rochester.edu/legacy/Forth/stack.html (http://astro.pas.rochester.edu/legacy/Forth/stack.html). Where I have drop it would remove the top item from the stack.

#3
In the video I saw an "lt", and it seemed to have the same function as less than. So, in my code, I use a "gt" for greater than.

#4
Also in my code, I use a variable. I set it up like Virgil's GetTimer0 and SetTimer0 in the video, but I'm not certain that's how it would be written.

#5
I think that what my code does requires either

1. a variable
or
2. a way to interchange items on the stack

Which would be more cpu intensive?

#6
The loops I use are large, would it perhaps go over a limit on loop size? If so, how could that be avoided?

#7
In what order does the loop execute? Does it start at 600 then go to 1, or the other way around? Does the larger number have to be first?


In case I did something wrong, I want you to be able to correct me exactly. So, here is how I foresee the stack history as it executes this code:

1 1 1 1 GetCreeper SetVar0 GetVar0

#1
#1 1
#1 1 1
#1 1 1 1
#1 1 (1 1 Creeper Amount)
#1 1
#1 1 (1 1 Creeper Amount)

I J GetCreeper GetVar0 gt if

#1 1 X
#1 1 X Y
#1 1 (X Y Creeper Amount)
#1 1 (X Y Creeper Amount) (1 1 Creeper Amount)
#1 1 (True/False)
#1 1

#if (X Y Creeper Amount) > (1 1 Creeper Amount)

drop drop I J I J GetCreeper SetVar0

#1
#Empty
#X
#X Y
#X Y X
#X Y X Y
#X Y (X Y Creeper Amount)
#X Y

#1

I J GetCreeper GetVar0 gt if

#X Y A
#X Y A B
#X Y (A B Creeper Amount)
#X Y (A B Creeper Amount) (X Y Creeper Amount)
#X Y (True/False)
#X Y

#if (A B Creeper Amount) > (X Y Creeper Amount)

drop drop I J I J GetCreeper SetVar0

#X
#Empty
#A
#A B
#A B A
#A B A B
#A B (A B Creeper Amount)
#A B

#Goto #1. Repeat until finished.


This should finish with a single X and Y coordinate pair where the creeper is deepest (or tied for deepest). This code would go where I previously put GetDeepestCreeperCoords.
Title: Re: CRPL Ideas/Questions
Post by: Michionlion on December 28, 2012, 06:14:43 PM
variables are already implemented, use <-varName to push a var onto the stack, ->varName to pop an item from the stack and put it in a variable.  also, 'drop' is 'pop'.  And from my experience, yes, the stack is not cleared after every line.
Title: Re: CRPL Ideas/Questions
Post by: tornado on January 06, 2013, 04:11:17 AM
wait in the video Virgil entered current cords to emit creeper from the crpl tower
but what if you enter a random location on the map
Title: Re: CRPL Ideas/Questions
Post by: Michionlion on January 06, 2013, 07:22:30 AM
Quote from: tornado on January 06, 2013, 04:11:17 AM
wait in the video Virgil entered current cords to emit creeper from the crpl tower
but what if you enter a random location on the map

CurrentCoords just pushes two values onto the stack - your current x coord, and your current y coord.  If you put random numbers there, then the tower would create creeper at those coords.
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on January 06, 2013, 09:51:24 AM
Quote from: tornado on January 06, 2013, 04:11:17 AM
wait in the video Virgil entered current cords to emit creeper from the crpl tower
but what if you enter a random location on the map
Hello Tornado.

That was a good catch. Conceptually there is a disconnection between a tower's physical location and the actions it can take. Which is why Virgil will be introducing a "hidden" tower type. (More about this in a second - it gets very complicated.)  You should really think of a tower as merely a vehicle to introduce programming capability to a map.  The tower can affect terrain; launch spores; create Digitalis or runners; create or alter creeper and anti-creeper at any location on a map.

Destroying the tower might not even be a game completion option (or it may - there are special actions the tower con perform once, when it gets destroyed),

To avoid the visual confusion that may arise when a tower performs remote actions, and when destruction of the tower is not a game objective, the map maker can designate the tower as hidden - it won't appear on the map, yet it will still perform actions on that map.

HTH.
Title: Re: CRPL Ideas/Questions
Post by: 4xC on January 10, 2013, 03:23:07 PM
After seeing all of this, I have to say (assuming it has not been already; I could not make out everything at once because so much space is occupied, and too many words make it hard for me too frankly) there should just be a portion on the future CW3 page that has as complete of a CPRL tower dictionary as possible when the release finally comes.

Looking at this whole thread made me also feel like I was looking into a near-infinite debate between about 100 cooks, all in different 5-star restaurants making up their own dishes, all intended to be better than their last ones even though the first one is already good enough to eat according to customer reviews and not worth actively expanding its taste detail as fast as the cooks think.

In other words, this topic is too early if you ask me.
Title: Re: CRPL Ideas/Questions
Post by: 1158511 on January 10, 2013, 06:11:12 PM
Is CRPL aware of player "economy", destructive power, and expansion? Can exponential equations be used to model creeper output? Can the emitter remove creeper? Does it support pulsing emitters, such one period of high emitting, followed by a lower form? I don't actually expect anyone to have any actually experience with the coding language, and if so this topic may be premature, however I am deeply curious, as it pertains to new idea of variable amount emitters as opposed to static amount emitters. I am looking forward toward this awesome idea, and I am excited to see what the community can make with it

Title: Re: CRPL Ideas/Questions
Post by: Ronini on January 10, 2013, 07:33:31 PM
Quote from: 1158511 on January 10, 2013, 06:11:12 PM
Is CRPL aware of player "economy", destructive power, and expansion? Can exponential equations be used to model creeper output? Can the emitter remove creeper? Does it support pulsing emitters, such one period of high emitting, followed by a lower form? I don't actually expect anyone to have any actually experience with the coding language, and if so this topic may be premature, however I am deeply curious, as it pertains to new idea of variable amount emitters as opposed to static amount emitters. I am looking forward toward this awesome idea, and I am excited to see what the community can make with it


As far as I know, all of the above (except probably the exponatial equations, but my guess would be they, too) are possible with the crpl.
Title: Re: CRPL Ideas/Questions
Post by: lurkily on January 10, 2013, 08:33:33 PM
Exponential equations can be done with simple  multiplication. 

If you script the crpl towers to emit in a pulsing pattern, high then low then high then low, etc, then they will.

"Set creeper" is used in the demonstration.  I presume that if you set creeper to a level lower than what is already present (such as zero) then it will, in effect, be removing creeper.

I agree that this thread is probably premature.  Wait until you can hold it in your hands and turn it around to see all sides of it.  Then a lot of what has been speculated about will be very obvious, and the ideas and flights of fancy that you can carry it to will go far beyond what you can envision right now.
Title: Re: CRPL Ideas/Questions
Post by: Kingo on January 10, 2013, 08:37:16 PM
People can't help getting excited over something like this and asking questions.
For me, it's going to be the best part of CW3.
Title: Re: CRPL Ideas/Questions
Post by: lurkily on January 10, 2013, 09:11:48 PM
Not enough information is out yet for people to know what questions are important. 

Not saying people shouldn't be excited.  Just that speculation at this point is to a large degree, wild and aimless.
Title: Re: CRPL Ideas/Questions
Post by: 1158511 on January 10, 2013, 09:59:33 PM
Indeed, life may be wild and aimless, but that doesn't mean the majority of humanity isn't going to earn large degrees, or stop speculating. Perhaps it not the information that is important but the question.

"The important thing is not to stop questioning. Curiosity has its own reason for existing." -Albert Einstein
Title: Re: CRPL Ideas/Questions
Post by: lurkily on January 10, 2013, 11:28:07 PM
That's my point - the right question is important.  Right now not enough is known to ask the right question.  I never said people should not speculate.
Title: Re: CRPL Ideas/Questions
Post by: 4xC on January 11, 2013, 07:42:58 AM
Quote from: lurkily on January 10, 2013, 09:11:48 PM
Not enough information is out yet for people to know what questions are important. 

Not saying people shouldn't be excited.  Just that speculation at this point is to a large degree, wild and aimless.

Just what I have been saying here in a nutshell.
Title: Re: CRPL Ideas/Questions
Post by: florrat on January 16, 2013, 12:14:31 PM
And with the new video CRPL was brought to a whole new level making it way more epic! ;D (I had to grin when Virgil said something like "but you probably don't want to look at the code right now" just after I paused the video every second to read every piece of code he showed :) )
Title: Re: CRPL Ideas/Questions
Post by: Ronini on February 08, 2013, 01:16:38 AM
Are you able to define your own functions in CRPL?
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on February 08, 2013, 01:27:25 AM
Quote from: Ronini on February 08, 2013, 01:16:38 AM
Are you able to define your own functions in CRPL?

If by "function" you mean "a collection of instructions/commands that can be invoked from multiple other locations", then yes.

If you mean "can I write my own new code that does something not defined by the CRPL instruction set", then no.
Title: Re: CRPL Ideas/Questions
Post by: dlbushman on May 02, 2013, 02:54:08 PM
Long time forum creeper, first time poster  ;D

Any chance we could get a copy of the CRPL script Virgil shows in the videos?  Mainly the more complex ones.  It does say earlier in this thread that the full CRPL API wouldn't be available, I'm assuming, until the game is released.  I've thought about going through the videos and just pausing and copying it down, but that seems tedious (unless someone has already done that :) )

I'm very much looking forward to playing CW3 and playing around with CRPL.
Title: Re: CRPL Ideas/Questions
Post by: knucracker on May 02, 2013, 03:16:48 PM
Welcome!

Here is a complex example. Not for the inexperienced coder...  The comments describe what it does.  This code was written using pure RPN notation (postfix notation).  CRPL also supports prefix and infix notation.  So
3 4 add        
3 add(4)        
add(3 4)        
all mean the exact same thing to the compiler.  I tend to use prefix notation a fair amount these days, but when this script was written I didn't yet support the warp operator "()" in CRPL, so it was all done in postfix.


# Patrol.crpl
# Created on: 2/2/2013 2:29:11 PM
# When attached to a unit, the unit will move around on terrain
# that is equal to the starting terrain height.  Can be used to
# create a train, or a patrolling unit that follows a 'rail' made
# out of terrain.  When the unit is faced with a choice of direction
# a random direction is chosen.  The unit also will not move back onto
# its previous location unless there is no other choice.
# ------------------------------------------

$SPEED:2

once
# Grab the current terrain height and remember this.
# We only move onto terrain that is equal to the starting height.
CurrentX CurrentY GetTerrain ->targetTerrainHeight

# Initialize our last position since we don't have one.
-1 ->lastCellX
-1 ->lastCellY

self CONST_CREATEPZ FALSE SetUnitAttribute
endonce

<-dieing if
GetTimer0 eq0 if
self 2 Destroy
endif
return
endif

#If we aren't moving, choose a new location.  The location will be a neighboring cell.
GetQueuedMoveCount eq0 if
<-base CONST_ISDESTROYED GetUnitAttribute if
true ->dieing
30 150 RandInt SetTimer0
return
endif

@ChooseNewCell if
<-chosenX <-chosenY <-SPEED QueueMove
CurrentX ->lastCellX
CurrentY ->lastCellY
endif
endif


:ChooseNewCell
-1 ->chosenX
-1 ->chosenY

# Get a list of the neighbors that we can move to.
# This call returns the coordinate pairs on the stack.
@GetPossibleCells

# Choose a random location within the list
0 <-count RandInt ->randCellNumber

# Go through the list and pop all of the coordinates off the stack
# As we pass the coordinates that we chose in our random number above, remember them.
# Those are the coordinates we will be returning.
<-count 0 do
->y
->x
I <-randCellNumber eq if
<-x ->chosenX
<-y ->chosenY
endif
loop
# Return if we chose a new location
<-chosenX -1 neq


:GetPossibleCells
#Check the four neighboring cells to see if they are the same terrain height.
0 ->count
CurrentX 1 add ->cx CurrentY ->cy @CheckCell #Right
CurrentX ->cx CurrentY 1 sub ->cy @CheckCell #Up
CurrentX 1 sub ->cx CurrentY ->cy @CheckCell #Left
CurrentX ->cx CurrentY 1 add ->cy @CheckCell #Down

# By default, we won't return the last cell coordinates.  This is so the patrolling unit
# doesn't return back to where it came from immediately.  But, if the only choice is to return
# to the previous cell, then that is what we have to do.
<-count eq0 if
<-lastCellX
<-lastCellY
1 ->count
endif


:CheckCell
#Check to see if the cell we are looking at is the last cell, if so ignore.
<-cx <-lastCellX neq <-cy <-lastCellY neq or if
# Check if the target cell is at our target terrain height.  If so, push the
# coordinates to the stack and increment count.
<-cx <-cy GetTerrain <-targetTerrainHeight eq if
<-cx
<-cy
<-count 1 add ->count
endif
endif


:destroyed
<-base neq0 if
<-base "Base.crpl" "patrolCount" GetScriptVar ->patrolCount
<-patrolCount 1 sub ->patrolCount
<-base "Base.crpl" "patrolCount" <-patrolCount SetScriptVar
endif
Title: Re: CRPL Ideas/Questions
Post by: JH on May 04, 2013, 03:09:30 AM
Wait, isn't that the same code used for those moving machines in your Aether video?
Title: Re: CRPL Ideas/Questions
Post by: Grauniad on May 04, 2013, 07:40:58 AM
Yes.
Title: Re: CRPL Ideas/Questions
Post by: dlbushman on May 04, 2013, 07:46:19 PM
Quote from: JH on May 04, 2013, 03:09:30 AM
Wait, isn't that the same code used for those moving machines in your Aether video?
That's exactly what it is and I've actually managed to understand most of it.  It's well commented, which helps a lot.  I've got a degree in MIS and I've coded in Java, COBOL, PL/SQL and others, but nothing stack based or using RPL, so I'm trying to learn.  I've played around a little with the Forth interpreter that was posted and I'm slowly getting it.

There are other chunks of code that govern the "Base" that spits out the moving CRPL towers that isn't there.  There is also code that governs the beam that kills things.  I have a bunch of questions about the code, nothing that can't wait.  It was very cool to start looking at this, and to see how the CRPL tower patrol code works.