递归求解Bubble Blast 2最少步数时结构体修改的处理方法
问题背景
使用C语言搭配ncurses库复刻Play Store平台游戏《Bubble Blast 2》,目前已完成游戏物理逻辑的编码,需要实现计算通关最少移动步数的功能。
核心问题
游戏所有状态数据均存储在自定义结构体中,递归计算步数的函数需要调用该结构体,且游戏运行过程中物理逻辑会持续修改该结构体;递归函数必须复用现有会修改结构体的游戏物理逻辑代码,因此需要解决:
当结构体会被游戏物理逻辑修改时,如何在递归流程中正确使用该结构体?
涉及的游戏结构体定义
struct game; typedef struct point { int x; int y; } POINT, *POINT_P; typedef struct bubble { POINT point; int state; } BUBBLE, *BUBBLE_P; typedef struct bubbles { BUBBLE* bubbles; int length; int allocated; } BUBBLES, *BUBBLES_P; typedef struct projectile { POINT point; char direction; int restoreChar; int restoreColor; } PROJECTILE, *PROJECTILE_P; typedef struct projectiles { PROJECTILE* projectiles; int length; int allocated; } PROJECTILES, *PROJECTILES_P; typedef struct game { BUBBLES bubbles; PROJECTILES projectiles; int rows; int columns; int selected; int array[6][5]; int moves; int minMoves; bool finished; bool movesCalc; } GAME, *GAME_P;
其余代码均为游戏物理逻辑,核心特征是游戏运行过程中会修改上述结构体,因此暂未提供;如果解答需要更多代码作为支撑,会第一时间补充。
内容的提问来源于stack exchange,提问作者Jackrin
相关产品推荐
相关产品推荐

