Despite the delay, I am still working on my AI/robot game thing. A while ago I added what I said would be my next steps, but never posted about it. So I’m doing that now.
I feel that Finite State Machines (FSMs) are a useful concept
for automations such as robots. So, I added language-level support for them.
I added a state function of the form
(state variable default state1 state1action...).
variable is the variable in which the state information is stored.
default is what action to take then the state is invalid or undefined.
default argument are pairs of state names and state actions.
All state actions, including the
default action must return which
state to go to next. This can be paired with
(do ...) calls to do multiple
things within the state, and
(if ...) calls allow you to branch to
different states conditionally.
At its core, the FSM support I added is basically a C style switch
where every case assigns to the variable being switched on, including
the default case. So, I figured I should also add a regular switch statement,
(switch value default case1 case1action) where
value is the value to
default is the action to do if no case matches the value,
and following those are pairs of values and actions, where the actions
are performed only if the case before them matches the value being switched on.
Some trickery lets you use
switch as an
(if ...) else chain, as the
language does not support else.
(switch #t (ELSE CODE) (CONDITION1) (WHAT TO DO IF CONDITION1) (CONDITION2) (WHAT TO DO IF CONDTIION2 BUT NOT CONDITION1) (CONDITION3) (WHAT TO DO IF CONDITION3 BUT NOT THE PRIOR ONES)... )
In the prior code, by switching on
#t (the true literal), we
execute the action corresponding to the first true case, just like
an if … else if … else if … else if … chain in C.
I also added a few featurs for the robot part of things. I finally
made the wheels turn corresponding to their speeds. I also added support
for basic telemetry and debugging, as that is very useful.
(log message) will append
message to a text block beneath the game
view. This text block only shows messages logged during the last game
frame, so it is not like a long console log.
Finally, I started playing around with adding a gyroscope sensor, which
reports change in rotation. Below I show off the new gyroscope and logging.