蛮力法解字谜游戏(未完成)_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 蛮力法解字谜游戏(未完成)

蛮力法解字谜游戏(未完成)

 2014/5/18 13:20:29  lixuanbin  程序员俱乐部  我要评论(0)
  • 摘要:时差爆发,睡不着,闲的蛋疼。。。思路写在注释里,直接撸代码:importjava.util.*;publicclassWordPuzzle{privatechar[][]puzzle;privateList<String>wordList;publicWordPuzzle(char[][]puzzle,List<String>wordList){this.puzzle=puzzle;this.wordList=wordList;}/***Solvethepuzzle
  • 标签:游戏

时差爆发,睡不着,闲的蛋疼。。。思路写在注释里,直接撸代码:

class="java" name="code">import java.util.*;
public class WordPuzzle {
    private char[][] puzzle;
    private List<String> wordList;

    public WordPuzzle(char[][] puzzle, List<String> wordList) {
        this.puzzle = puzzle;
        this.wordList = wordList;
    }
    
    /**
     * Solve the puzzle.<br/>
     * result: {beginIndex(row, column);endIndex(row, column);matchWord}<br/>
     * temp tuple: {beginIndex(row,column);endIndex(row,column);direction;composedChars2String}<br/>
     * Procedure:<br/>
     * for each element in the puzzle {<br/>
     *     construct a tuple;<br/>
     *     check word list and see whether there is a match;<br/>
     * }
     */
    public List<String> solvePuzzle() {
        List<String> resultList = new LinkedList<String>();
        List<String> tupleList = null;
        String tempResult = null;
        String[] strings = null;
        for(int i = 0; i < puzzle.length; i++) {
            for(int j = 0; j < puzzle[i].length; j++) {
                tupleList = findAllString(i, j);
                for(String temp : tupleList) {
                    strings = temp.split(";");
                    if(wordList.contains(strings[1])) {
                        tempResult = "(" + i + "," + j + ");" + strings[0] + ";" + strings[1];
                        resultList.add(tempResult);
                        tempResult = null;
                    }
                }
            }
        }
        return resultList;
    }

    /**
     * Find all possible composed strings and return as a list along with the end index.<br/>
     * eg. {(row,column);string}
     */
    private List<String> findAllString(int beginRow, int beginColumn) {
        List<String> resultList = new LinkedList<String>();
        List<String> tempList = null;
        tempList = findAllRow(beginRow, beginColumn);
        Collections.copy(resultList, tempList);
        tempList = findAllColumn(beginRow, beginColumn);
        Collections.copy(resultList, tempList);
        tempList = findAllDiagonal(beginRow, beginColumn);
        Collections.copy(resultList, tempList);
        return resultList;
    }

    private List<String> findAllRow(int i, int j) {return null;}

    private List<String> findAllColumn(int i, int j) {return null;}

    private List<String> findAllDiagonal(int i, int j) {return null;}
}

?

?

发表评论
用户名: 匿名