我如何编码这个问题? (C ++) [英] How can I code this problem? (C++)

查看:232
本文介绍了我如何编码这个问题? (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个简单的游戏,将数据集存储在2D网格中(如棋盘)。网格中的每个单元格可以包含一个整数(0表示单元格为空)。如果单元格包含数字> 0,则称为填充。网格上的填充单元格集称为配置。



我的问题是能够识别特定配置,单元格的配置在MxN网格中。



问题(在我看来),分解成以下2个子问题:


$不知怎的,正规化配置的位置(例如,将其位置重定基为(0,0),使得包含所有单元格的最小矩形配置在MxN网格中具有其左顶点(0,0)
  • 计算某种相似性度量(或者可以简单地设置差异?如果当前的正规化配置是已知配置(即已识别)之一


  • 将需要使用std :: set(我迄今为止还没有使用的少数STL容器之一,在我所有的年份作为一个C ++编码器!)我会感谢任何人的任何想法/提示,解决了这样的问题。任何代码片段,伪代码和/或链接都会非常有用。

    解决方案

    相似性度量是一个巨大的学术研究领域。你需要决定你的任务需要什么级别的复杂性。它可能是,你可以简单地拖动模板模式横跨你的板,光栅风格,并为每个位置得分+1的命中和-1的错过和总和的分数。然后找到模板获得最高分数的位置。然后,此score_max是该模板的相似性指标。如果这种方法不足,你可能需要进入更多的细节关于游戏的精确性质。


    I am writing a simple game which stores datasets in a 2D grid (like a chess board). Each cell in the grid may contain a single integer (0 means the cell is empty). If the cell contains a number > 0, it is said to be "filled". The set of "filled" cells on the grid is known as a "configuration".

    My problems is being able to "recognize" a particular configuration, regardless of where the configuration of cells are in the MxN grid.

    The problem (in my mind), breaks down into the following 2 sub problems:

    1. Somehow "normalising" the position of a configuration (for e.g. "rebasing" its position to (0,0), such that the smallest rectangle containing all cells in the configuration has its left vertice at (0,0) in the MxN grid

    2. Computing some kind of similarity metric (or maybe simply set difference?), to determine if the current "normalised" configuration is one of the known configurations (i.e. "recognized")

    I suspect that I will need to use std::set (one of the few STL containers I haven't used so far, in all my years as a C++ coder!). I would appreciate any ideas/tips from anyone who has solved such a problem before. Any code snippets, pseudocode and/or links would be very useful indeed.

    解决方案

    Similarity metrics are a massive area of academic research. You need to decide what level of sophistication is required for your task. It may be that you can simply drag a "template pattern" across your board, raster style, and for each location score +1 for a hit and -1 for a miss and sum the score. Then find the location where the template got the highest score. This score_max is then your similarity metric for that template. If this method is inadequate then you may need to go in to more detail about the precise nature of the game.

    这篇关于我如何编码这个问题? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆