1. mortaza
  2. برنامه‌نویسی و طراحی وب
  3. یکشنبه, 24 آذر 1392
سلام چرا این برنامه اجرا میشه
**********************************************************************/
* This will use human logic to attempt to solve a board
* It will add the total number of possibles for each number
* in each ROW, COLUMN, and BLOCK…
* If the total is one it will fill that number in and update the possibles
* in each square with the function checkPossibles
***********************************************************************/
float solve(Board &newBoard)
{
int coordinates = 0;
bool noChanges;
int startTime = clock();
do
{
noChanges = true;

//Fill in one possible answer squares and exit if solved
//We will do this after each Row, Column, and Block check
if (checkPossibles(newBoard))

return true;

//Fill in the known numbers for each ROW
for (int i = 0; i < 81; i += 9)
for(int guess = 1; guess <= 9; guess++)//Numbers 1 to 9
{
int total = 0;

//Test the number on the row
for(int iRow = i; iRow < (i + 9); iRow++)
if(!newBoard.isFixedValue[iRow])
total += newBoard.isPossibleValue[iRow][guess - 1];

if (total == 1)//We have found an answer!
for(int iRow = i; iRow < (i + 9); iRow++)
if (newBoard.isPossibleValue[iRow][guess - 1] &&
!newBoard.isFixedValue[iRow])
{
newBoard.values[iRow] = guess;
newBoard.isFixedValue[iRow] = true;
noChanges = false;
}
}

//Fill in one possible answer squares and exit if solved
if (checkPossibles(newBoard))
return true;

//This will fill in the known numbers for each COLUMN
for (int i = 0; i < 9; i++)
for(int guess = 1; guess <= 9; guess++)//Numbers 1 to 9
{
int total = 0;

//Test the number on the column
for(int iColumn = i; iColumn < 81; iColumn += 9)
if(!newBoard.isFixedValue[iColumn])
total += newBoard.isPossibleValue[iColumn][guess - 1];

if (total == 1)//We have found an answer!
for(int iColumn = i; iColumn < 81; iColumn += 9)
if (newBoard.isPossibleValue[iColumn][guess - 1] &&
!newBoard.isFixedValue[iColumn])
{
newBoard.values[iColumn] = guess;
newBoard.isFixedValue[iColumn] = true;
noChanges = false;
}

}

//Fill in one possible answer squares and exit if solved
if (checkPossibles(newBoard))
return true;

//This will fill in the known numbers for each BLOCK
for (int r = 0; r < 81; r += 27)
for (int c = 0; c < 9; c += 3)
{
int i = r + c;//Puts me at the beginning of each block
for(int guess = 1; guess <= 9; guess++)//Numbers 1 to 9
{
int total = 0;

//Test the number on the column
for(int iBlockR = i; iBlockR < (i + 27); iBlockR += 9)
for (int iBlockC = iBlockR; iBlockC < (iBlockR + 3); iBlockC++)
if(!newBoard.isFixedValue[iBlockC])
total += newBoard.isPossibleValue[iBlockC][guess - 1];

if (total == 1)//We have found an answer!
for(int iBlockR = i; iBlockR < (i + 27); iBlockR += 9)
for (int iBlockC = iBlockR; iBlockC < (iBlockR + 3); iBlockC++)
if (newBoard.isPossibleValue[iBlockC][guess - 1] &&
!newBoard.isFixedValue[iBlockC])
{
newBoard.values[iBlockC] = guess;
newBoard.isFixedValue[iBlockC] = true;
noChanges = false;
}
}
}

//Fill in one possible answer squares and exit if solved
if (checkPossibles(newBoard))
return true;
}while(noChanges == false);

//If not solved by now, Time to use the big guns
if (!isSolved(newBoard))
bruteForce(newBoard);

//Output time it took to solve board
return (clock() - startTime) / 1000.0;
}
امیرحسین بهترین پاسخ Pending Moderation
0
رای
پس‌گیری
این برنامه که کامل نیست فقط یکی از توابع برنامس اگه امکانش هست کل برنامه رو بزار تا بشه فهمید مشکلش چیه
  • صفحه :
  • 1


هنوز پاسخی به این پست ارسال نشده است.
البته از آنجایی که هنوز در سایت لاگین نکرده‌اید، اجازه‌ی پاسخ دادن به این پست را ندارید.

ورود / ثبت‌نام

 

کاربران فعال این ماه

AMIR
Super User
مسعود یوسف‌نژاد
نازنین امامی
علی مردانی