Learning from AI while making a game out of a random walk simulation
I submitted a game called Sticky 8 last week inspired by a puzzle from Quanta Magazine. The puzzle is about understanding entropy in a toy universe, whereas my game is just about letting a figure 8 remain unlit (in that puzzle's terminology, keeping the entropy from reaching its minimum). It is made with help from an AI agent (the free one showcased in this starter article). Since this game did not fit in any of the familiar game categories, the AI asked quite a few questions regarding what I meant by bars sticking on a 7-segment display, what was to be scored, what was to be penalized, what kind of timings I was after, etc? After answering those questions as best as I could and half a dozen iterations trying to fix the "timings" & "characters limit" issues, a more or less working version was ready. I tweaked this last version a lot myself to bring the character count down to "4999" as I ran out of agent's "free time" for the day! 😂
Anyway, two interesting things I learnt from the agent (the first was done by the agent on its own while the second was suggested by me):
- Input Guard: Retain a screen for a bit longer by ignoring accidental button/space presses like after a round's result is displayed. For this purpose set a state variable "S.gd=0.6;" (for 0.6s delay) as the result screen loads. Let that variable decrease by "dt" in the updateState() function: "S.gd=S.gd-dt;". And before the next round loads, check not just for "pressed" state but also "S.gd<=0". Bingo! Your game player is not frustated by their best score vanish right before their eyes.🥳
- Title Fly-out: This powerpoint-style transition effect was quite easily implemented (by the agent). Here's the problem description: the title on the title screen is to be animated from its prominent screen position to the top of the screen, while its fontsize decreases and its colour fades to white. The following code loops inside the "renderFrame()" function (with the initialization code setting "S.anT=s.t;" and "S.t" increasing with "dt" somewhere in the "updateState()" function):
p = min(max((S.t - S.anT)/.9, 0), 1); %0.9s is the time duration for the animation
pe = p^2 * (3 - 2*p); % smooth-step easing!?
set(G.titleH, Position=[2.5,3.5+.591*pe], FontSize=38-22*pe, Color=cg+([1 1 1]-cg)*pe);
%So the header title's Position(2) changes from 3.5 to 4.091; Fontsize changes
%from 38 to 16; Color changes from cg=[1 0 1] to [1 1 1]=w smoothly!

That's all for now. Enjoy!🎉
2 个评论
时间降序I gave you vote on this one after glancing through your code. In my opinion, it is a creative application of mathematical random walk theory, translated into an engaging one button game. Notable technical strengths include compact edge encoding (hE,vE), efficient state management, the two step random walk (stp()), and elegant smoothstep interpolation for the title animation. The input guard (S.gd) also demonstrates thoughtful usability by preventing accidental scene transitions. The accompanying post provides valuable insights into iterative human AI collaboration and MATLAB code optimization.
Overall, an excellent combination of mathematical modelling, efficient MATLAB programming, and innovative game design.
登录以参与