Skip to content

Instantly share code, notes, and snippets.

@lessandro
Last active December 10, 2015 21:08
Show Gist options
  • Select an option

  • Save lessandro/4492323 to your computer and use it in GitHub Desktop.

Select an option

Save lessandro/4492323 to your computer and use it in GitHub Desktop.
GridC bot - walk randomly
CALL << @main
END
@move1
# assign dir
# call rand
PUSH 3
RAND
# call equal
# ["dir"]
PEEK << -1
PUSH 0
EQUAL
IFFGOTO << @L0
# call ffi
PUSH @MOVE
PUSH @NORTH
CALLFF << 2
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L1
@L0
# scope exit, pop []
POPN << 0
@L1
# call equal
# ["dir"]
PEEK << -1
PUSH 1
EQUAL
IFFGOTO << @L2
# call ffi
PUSH @MOVE
PUSH @SOUTH
CALLFF << 2
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L3
@L2
# scope exit, pop []
POPN << 0
@L3
# call equal
# ["dir"]
PEEK << -1
PUSH 2
EQUAL
IFFGOTO << @L4
# call ffi
PUSH @MOVE
PUSH @EAST
CALLFF << 2
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L5
@L4
# scope exit, pop []
POPN << 0
@L5
# call equal
# ["dir"]
PEEK << -1
PUSH 3
EQUAL
IFFGOTO << @L6
# call ffi
PUSH @MOVE
PUSH @WEST
CALLFF << 2
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L7
@L6
# scope exit, pop []
POPN << 0
@L7
PUSH 0
STORE retval
# ret, pop locals ["dir"]
POPN << 1
PUSH retval
RETURN
# scope exit, pop ["dir","0"]
POPN << 2
# end @move1
@eat
# call ffi
PUSH @LOOK
PUSH @NORTH
CALLFF << 2
IFFGOTO << @L8
# call ffi
PUSH @PULL
PUSH @NORTH
CALLFF << 2
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L9
@L8
# scope exit, pop []
POPN << 0
@L9
# call ffi
PUSH @LOOK
PUSH @SOUTH
CALLFF << 2
IFFGOTO << @L10
# call ffi
PUSH @PULL
PUSH @SOUTH
CALLFF << 2
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L11
@L10
# scope exit, pop []
POPN << 0
@L11
# call ffi
PUSH @LOOK
PUSH @EAST
CALLFF << 2
IFFGOTO << @L12
# call ffi
PUSH @PULL
PUSH @EAST
CALLFF << 2
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L13
@L12
# scope exit, pop []
POPN << 0
@L13
# call ffi
PUSH @LOOK
PUSH @WEST
CALLFF << 2
IFFGOTO << @L14
# call ffi
PUSH @PULL
PUSH @WEST
CALLFF << 2
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L15
@L14
# scope exit, pop []
POPN << 0
@L15
PUSH 0
STORE retval
# ret, pop locals []
POPN << 0
PUSH retval
RETURN
# scope exit, pop ["0"]
POPN << 1
# end @eat
@main
@L16
PUSH 1
IFFGOTO << @L17
# call move1
CALL << @move1
# pop expr stm
POP
# call eat
CALL << @eat
# pop expr stm
POP
# scope exit, pop []
POPN << 0
GOTO << @L16
PUSH @L16
@L17
PUSH 0
STORE retval
# ret, pop locals []
POPN << 0
PUSH retval
RETURN
# scope exit, pop ["0"]
POPN << 1
# end @main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment