Click here to Skip to main content
15,892,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Can edit box be set as array? Pin
akira3229-Feb-04 1:19
akira3229-Feb-04 1:19 
GeneralRe: Can edit box be set as array? Pin
Anonymous1-Mar-04 14:23
Anonymous1-Mar-04 14:23 
GeneralATTACH_PARENT_PROCESS value Pin
Anonymous28-Feb-04 22:33
Anonymous28-Feb-04 22:33 
GeneralRe: ATTACH_PARENT_PROCESS value Pin
Gary R. Wheeler29-Feb-04 5:31
Gary R. Wheeler29-Feb-04 5:31 
QuestionCan we use ConvertSidToStringSid in VC++6.0 and Windows2000? Pin
mctpursuer28-Feb-04 22:17
mctpursuer28-Feb-04 22:17 
AnswerRe: Can we use ConvertSidToStringSid in VC++6.0 and Windows2000? Pin
Gary R. Wheeler29-Feb-04 6:28
Gary R. Wheeler29-Feb-04 6:28 
AnswerRe: Can we use ConvertSidToStringSid in VC++6.0 and Windows2000? Pin
Michael Dunn29-Feb-04 6:37
sitebuilderMichael Dunn29-Feb-04 6:37 
GeneralKnights Tour Pin
Pharacyde28-Feb-04 21:10
Pharacyde28-Feb-04 21:10 
The following program is an attempt at the knights tour using backtracking/recursion. This was for an assignment in my class, which is now past due. The code below is what I turned in. This thing has been driving me nuts.

The problem is when it needs to backtrack, it seems to enter an infinite loop. I have commented out the problem area. When commented out, the knight will make moves, avoiding previously visited squares until it needs to back track... at that point, I need to replace the last square visited with 0 (make it blank) and decremet the total number of moves made, "k". Compiles w/ no errors or warnings.


//Begin Code
#include<iostream>
#include<iomanip>
#include<string>
#include "d_matrix.h"

using namespace std;

bool knight(matrix<int>& board, int k, int x, int y)
{
bool result;
int u, v, m=0;
int i = 0;
const int n = board.rows(); //n = rows
//all possible knight moves
static int dx[] = {2,1,-1,-2,-2,-1,1,2},
dy[] = {-1,-2,-2,-1,1,2,2,1};

board[x][y] = k; //k is initial position in x,y

if(k == n*n)
result = true;
else
{
result = false;

for(m=0; m <= 7; m++)
{
//while the tour has not been completed, and a valid move is available, continue
while((x + dx[m] <= 7) && (x + dx[m] >= 0)
&& (y + dy[m] <= 7) && (y + dy[m] >= 0) &&
(board[x + dx[m]][y + dy[m]] == 0))
{
//assign new position coordinates
u = x + dx[m];
v = y + dy[m];

k++; //move to next count
board[u][v] = k; //assign square iteration number

knight(board, k, u, v);
}
//board[u][v]=0; I THINK THE PROBLEM IS HERE!
//k--;
//result = false;
}
}
return result;
};


int main()
{
int n, x, y;
string str;


cout << "Enter the dimensions of the board with a single value: " << endl;
cin >> n;
cout << endl;
matrix<int> board(n,n,0);

while(str != "yes")
{
cout << "Enter the starting position for the knight in x y form: ";
cin >> x >> y;
cout << endl;



knight(board, 1, x, y);

//Draw Board *works*
int i,j, temp;

cout <<" 0 1 2 3 4 5 6 7" << endl;
for (i = 0; i < 8; i++)
{
cout << i << " ";
// draw the squares in current row
for (j = 0; j < 8; j++)
{

if (board[i][j])
{
temp = board[i][j];
if(temp < 10)
{
cout << " 0" << temp;
}
else
cout << " " << temp;
}
else if(board[i][j] == 0)
cout << " --";
else
cout << " xx";
}
cout << endl;
}
cout << "Quit? yes or no." << endl;
cin >> str;
cout << endl;
}
return 0;
}
//End Code
Generaltooltip for ListCtrl in MDI application Pin
Dudi Avramov28-Feb-04 21:03
Dudi Avramov28-Feb-04 21:03 
GeneralProblem to play and record wave files!!! Pin
Mehdi_Hosseinpour28-Feb-04 19:09
Mehdi_Hosseinpour28-Feb-04 19:09 
GeneralFirewalls &amp; VC++ FTP application again Pin
rasha200328-Feb-04 18:17
rasha200328-Feb-04 18:17 
GeneralDifficuties on Mouse Coordinates Detection Pin
ansontong28-Feb-04 17:32
ansontong28-Feb-04 17:32 
GeneralRe: Difficuties on Mouse Coordinates Detection Pin
akira3229-Feb-04 1:23
akira3229-Feb-04 1:23 
GeneralBeginner: Having trouble with LoadResource and Windows Pin
mjeb111128-Feb-04 13:49
mjeb111128-Feb-04 13:49 
GeneralRe: Beginner: Having trouble with LoadResource and Windows Pin
Gerald Schwab28-Feb-04 14:49
Gerald Schwab28-Feb-04 14:49 
GeneralRe: Beginner: Having trouble with LoadResource and Windows Pin
mjeb111128-Feb-04 16:02
mjeb111128-Feb-04 16:02 
GeneralRe: Beginner: Having trouble with LoadResource and Windows Pin
Gary R. Wheeler29-Feb-04 5:58
Gary R. Wheeler29-Feb-04 5:58 
GeneralRe: Beginner: Having trouble with LoadResource and Windows Pin
mjeb111129-Feb-04 12:12
mjeb111129-Feb-04 12:12 
GeneralDialogBar and Tab Controls Pin
krugger28-Feb-04 11:37
krugger28-Feb-04 11:37 
Generalregsvr32 and XP Pin
BaldwinMartin28-Feb-04 9:03
BaldwinMartin28-Feb-04 9:03 
GeneralDLL bitmap Pin
BaldwinMartin28-Feb-04 7:58
BaldwinMartin28-Feb-04 7:58 
GeneralRe: DLL bitmap Pin
Gary R. Wheeler29-Feb-04 6:22
Gary R. Wheeler29-Feb-04 6:22 
GeneralCaps Lock Pin
Archer28228-Feb-04 7:01
Archer28228-Feb-04 7:01 
GeneralRe: Caps Lock Pin
PJ Arends28-Feb-04 8:27
professionalPJ Arends28-Feb-04 8:27 
GeneralRe: Caps Lock Pin
Archer28228-Feb-04 8:32
Archer28228-Feb-04 8:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.