0
我想知道如何在java中自己創建一個拼圖求解器,但卡住了。我能夠讀取文件中的輸入,其中縱橫填字的維度存儲在數組中。我在搜索實際謎題中的單詞時遇到問題。這是我到目前爲止有:我想在java中創建一個填字遊戲拼圖求解器
package crossWrdNMaze2;
import java.io.File;
import java.util.Scanner;
public class crossWord {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(new File("puzzle.txt"));
//r and c describe the dimensions of the puzzle array
int r = sc.nextInt();
int c = sc.nextInt();
char[][] array = new char[r][c];
//to scan puzzle chars into two-dimensional array
for (int i = 0; i<r; i++){
String getChar = new String(sc.next());
for(int j=0; j<c; j++){
array[i][j] = getChar.charAt(j);
}//end for2
}//end for1
//Test to make sure array was filled
for(int i=0; i<r; i++){
for(int j=0;j<r;j++)
System.out.print(array[i][j]);
System.out.println("");
}//end for
//scan in the number of words to be found in array (these integers follow the lines of
//letters which make up the array in the text file
int num = sc.nextInt();
System.out.println(num);
for(int i=0; i<num; i++){
//scan in the first word to be found
String getWord = new String(sc.next());
//determine word length to find size of array to look for in puzzle
int z = getWord.length();
char array2[] = new char[z];
//scan new string (word we are looking for) into an array so we can look for one letter
//at time in puzzle
for(int j=0; j<z;j++){
array2[j] = getWord.charAt(j);
}//end for2
//Size two array for the purpose of passing by reference so we can get coordinates of
//word in puzzle
int[] result = new int[1];
//pass array(puzzle), array2(word we are looking for), result(coordinates of word in array),
//r(number of rows in puzzle), c (number of columns in puzzle), z (length of word we
//are searching for)
findWord(array, array2, result, r, c, z);
//print loaction of word each time through loop
System.out.println(getWord + " is located at position (" + result[0] + ") (" + result[1] + ")");
}//end for1
sc.close();
}//end main
static void findWord(char arr1[][], char arr2[], int[] result, int a, int b, int c){
for(int i=0; i<a;i++){
for(int j=0; i<b;j++){
for(int k = 0; k<c;k++){
if(arr1[i][j] != arr2[k]){
System.out.println("Word not found!");//test to see if comparing letters and giving false return
}else if(arr1[i][j]== arr2[k]){
System.out.println("progress");//test to check if returning true when correct
}//end if
}//end for3
}//end fosr2
}//end for1
}//end function
}//end class
編輯:我添加了一些意見的代碼,也是我剛剛從一篇文章我讀了最近 生日快樂堆棧溢出記得,我是一個很長一段時間的讀者但這是我第一次發佈。 再次感謝您的時間
wooo ...編輯你的文章,這個評論是不可讀的! – Gianmarco
您可能希望將您的功能從評論複製到帖子。使用'編輯'。 –
點擊您的問題下的[[edit]]選項,並通過評論中的其他信息進行更新。之後,刪除您的評論。 – Pshemo