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++)

}
4

1 回答 1

2

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

于 2010-12-09T09:44:50.627 回答