Last active
December 15, 2015 00:19
-
-
Save RyanBreaker/5172559 to your computer and use it in GitHub Desktop.
WIP solution to JohnEarnest's Forth Warrior. It looks, acts upon what is there, if it is a floor or stairs it will add that to the 'walkables' var. At 'move' it asks if it needs to think or not (if there's more than one possible path or not) and moves accordingly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( Current ToDo: | |
* Fix direction bug when picking up gem | |
* Figure out how to have it decide where to go when it has more than 1 path | |
) | |
: allot loop 0 , 1- dup while drop ; | |
create walkables 4 allot | |
create from -1 , | |
var n-dirs | |
: rot >r swap r> swap ; ( a b c -- c b a ) | |
: abs dup 0< if -1 / then ; ( n -- |n| ) | |
: add abs n-dirs @ + n-dirs ! ; ( flag -- ) | |
: resetVars 0 n-dirs ! ; ( -- ) | |
: walks@ walkables + @ ; ( dir -- flag ) | |
: walks! walkables + ! ; ( dir flag -- ) | |
# Looking words | |
: from? from @ = ; ( dir -- flag ) | |
: attack? SLIME = ; ( type -- flag ) | |
: take? dup GEM = swap KEY = or ; ( type -- flag ) | |
: walk? dup FLOOR = swap STAIRS = or ; ( type -- flag ) | |
: do? dup take? swap attack? or ; ( type -- flag ) | |
: act ( dir -- ) | |
dup from? if 0 swap walks! exit then | |
dup look | |
dup do? if | |
dup attack? if attack then | |
dup take? if take then FLOOR then | |
dup walk? dup add rot walks! drop | |
; | |
: search ( -- ) | |
N act | |
E act | |
S act | |
W act | |
; | |
# Moving words | |
: opp 2 + 4 mod ; ( dir -- opp ) # Opposite | |
: from! opp from ! ; ( dir -- ) | |
: Walk dup from! walk ; ( dir -- ) | |
: one-move ( -- ) | |
N walks@ if N Walk exit then | |
S walks@ if S Walk exit then | |
E walks@ if E Walk exit then | |
W walks@ if W Walk exit then | |
; | |
: multi-move one-move ; # Placeholder | |
: move ( -- ) | |
n-dirs @ | |
dup 1> if multi-move else | |
dup 1= if one-move else | |
-1 from ! then then drop | |
; | |
# Test loop | |
: brain | |
loop | |
search | |
move | |
resetVars | |
again | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment