生成类似填字游戏的数据集

发布于 2024-10-06 15:11:36 字数 1055 浏览 7 评论 0原文


我必须编写一个函数,它接受一个字符串列表(长度不同的单词)和一个 int(数据集的大小,例如 int 值 4 将是表中的 4 列和 4 行),并且我必须生成一个类似块的填字游戏(块是数据集),它将容纳列表中尽可能多的单词,就像填字游戏一样,如果字母在正确的位置匹配,它们可以相互交叉,并且单词必须全部混合在一起,从各个方向阅读(就像填字游戏一样)。

我似乎找不到代码来帮助我解决这个问题,到目前为止我已经有了数据集的基本结构,就在这里,任何帮助将不胜感激,谢谢。

public WordsDs WordMixer(List<string> wordList, int size)
{
    if ((wordList == null) || (size < 2))
    {
        return null;
    }

    //shuffle the words in the list so that they are in a random order
    Random random = new Random();
    var sortedList = wordList.OrderBy(i => random.Next()).ToList();

    //create a dataset for the words
    DataSet ds = new DataSet();
    DataTable dt = new DataTable();

    //add columns and rows according to the size parameter
    for (int i = 0; i < size; i++)
    {
        dt.Columns.Add(i.ToString(), typeof(string));
    }
    for (int i = 0; i < size; i++)
    {
        dt.Rows.Add(i);
    }


    for (int i = 0; i < wordList.Count; i++)
    {



    }//for (int i = 0; i < wordList.Count; i++)

}

I have to write a function that takes a list of string(words that vary in length), and an int(size of data set eg. int value of 4 will be 4 columns and four rows in table), and with this I must produce a crossword like block(block being the dataset) that will hold as many of the words in the list as possible, like a crossword they can cross each other if the letters match at the right places, and the words must be all mixed up, read in every direction(like a crossword puzzle).

I can't seem to find code to help me with this, so far I have the basic structure of the dataset, here it is, any help will be appreciated, thanks.

public WordsDs WordMixer(List<string> wordList, int size)
{
    if ((wordList == null) || (size < 2))
    {
        return null;
    }

    //shuffle the words in the list so that they are in a random order
    Random random = new Random();
    var sortedList = wordList.OrderBy(i => random.Next()).ToList();

    //create a dataset for the words
    DataSet ds = new DataSet();
    DataTable dt = new DataTable();

    //add columns and rows according to the size parameter
    for (int i = 0; i < size; i++)
    {
        dt.Columns.Add(i.ToString(), typeof(string));
    }
    for (int i = 0; i < size; i++)
    {
        dt.Rows.Add(i);
    }


    for (int i = 0; i < wordList.Count; i++)
    {



    }//for (int i = 0; i < wordList.Count; i++)

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

负佳期 2024-10-13 15:11:36

您可以只使用二维数组来保存字符。我想棘手的部分是从单词列表中找出两个单词之间共享一个字母的地方。我想从最不常用的字母开始,然后从那里开始工作!

有趣的文章
http://blogs.teamb.com/craigstuntz/2010/01/11 /38518/

堆栈溢出问题可能会有所帮助(尽管在 C++ 中 - 可能有用)
填字游戏搜索的最佳数据结构

代码生成器的其他链接。< br>
http://www.pscode.com/vb/脚本/ShowCode.asp?txtCodeId=6082&lngWId=10
http://dotnetslackers.com/articles/net/Creating- a-programming-crossword-puzzle.aspx
一分之一
http://pdos.csail.mit.edu/cgi-bin/theme-字

You could just use a two-dimensional array to hold the characters. I guess the tricky part is from the word list work out where there a letter is shared between two words. I guess start with the least frequently used letter and work from there!

Interesting Article
http://blogs.teamb.com/craigstuntz/2010/01/11/38518/

Stack Overflow Question may help (although in c++ - might be of use)
Best data structure for crossword puzzle search

Other links to code generators.
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=6082&lngWId=10
http://dotnetslackers.com/articles/net/Creating-a-programming-crossword-puzzle.aspx
One in c
http://pdos.csail.mit.edu/cgi-bin/theme-cword

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文