游戏图形设计?
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

this is a general question from my homework, I am just asking for some ideas or pseudo code.

Suppose I am constructing a tic-tac-toe game using C++. What I already have is a Node class which contains a const member data represents the current game board state, and an const array of pointer to other Nodes that contains every possible next-step state. So this will be a directed graph with out duplicated nodes(every node has its unique game state.).

I got a trouble when I am trying to generate such a graph. It seems like I need to use recursion because all data members in Node class are const so there's no way to change them around. And I can hardly come up with a good idea to generate such a graph at once without Node duplicated(I mean it will be easy to make it a tree, but it waste lots of space and time.). One thing may help is I am able to compare two different game states, and I don't think I am allowed to use any templet other than <set>.

So if anyone got any idea about this, please free to write down your thought or pseudo code. Thank you

#0

I think you need is to check for existence:

std::set< Node > checked_node;

bool isNodeChecked( Node ){
    return checked_node.find( Node )!=checked_node.end();
}

You need to overload something like operator = and operator < for std::set to work on your class Node;

Also std::unordered_map might work.

( Although as it seems to me that a tic-tac-toe status can be represented by non-negative integers from 0 to 3^9. In this way a std::set would suffice but you need extra encode decode functions.

推荐文章

自动关闭HTML标记

自动关闭HTML标记

推荐文章

iOS:映像不会从数组中删除

iOS:映像不会从数组中删除

推荐文章

宏扩展到预处理器块

宏扩展到预处理器块

推荐文章

没有有效的com.apple.developer网站.ubiquity kvstore标识符授权AD HOC iCloud

没有有效的com.apple.developer网站.ubiquity kvstore标识符授权AD HOC iCloud

推荐文章

闭合设计模式

闭合设计模式

推荐文章

从和到日期选取器场景

从和到日期选取器场景

推荐文章

Talend的JSON解析器

Talend的JSON解析器

推荐文章

MonoDroid中的GetItemIdAtPosition返回什么?

MonoDroid中的GetItemIdAtPosition返回什么?

推荐文章

Pattern和Matcher:如何将模式和字符串连接起来进行文件搜索

Pattern和Matcher:如何将模式和字符串连接起来进行文件搜索

推荐文章

如何更好地处理依赖于模板参数的类成员类型?

如何更好地处理依赖于模板参数的类成员类型?

推荐文章

如何为Linux编写底层设备驱动程序?

如何为Linux编写底层设备驱动程序?

推荐文章

是否有一种内置的方法可以反向使用JQuery的.each()?

是否有一种内置的方法可以反向使用JQuery的.each()?

推荐文章

按“返回”按钮关闭应用程序

按“返回”按钮关闭应用程序

推荐文章

有没有办法从收到的Iphone短信中获取发送者的电话号码?

有没有办法从收到的Iphone短信中获取发送者的电话号码?

推荐文章

OOO javascript:object self-reference返回未定义但控制台显示它存在

OOO javascript:object self-reference返回未定义但控制台显示它存在

推荐文章

C++中随机无符号字符值的生成

C++中随机无符号字符值的生成