GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-May-2004, 10:16
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough

Need a little coding help


Hello everyone,
I've run into a bit of a problem. What I'm trying to do is figure how to check if a move in a chess game is a valid move. What I'd like to do is construct one function that would work for the Rook, Bishop, and Queen. Does anyone have any suggestions?
  #2  
Old 26-May-2004, 11:33
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Why would you do that when the Rook, Bishop, and Queen all use different sets of moves? The Rook and Bishop do use subsets of the Queen's moves, but honestly, I don't think they could be combined to work for all 3. If I were you, I'd create a Move function for each type of chess piece instead of making it harder by trying to create one function to deal with 3 of them.
__________________
-Aaron
  #3  
Old 26-May-2004, 19:30
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Well, how does your chess board looks like?? is it an array?? can you show the codes for the boards and how you pieces into the board?? that would be helpful to provide a clear solution for you..

Assume the board is 2d array of 10X10, then you have to consider moves as North, East,West,South,NE,NW....
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #4  
Old 26-May-2004, 22:03
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by dabigmooish
Hello everyone,
I've run into a bit of a problem. What I'm trying to do is figure how to check if a move in a chess game is a valid move. What I'd like to do is construct one function that would work for the Rook, Bishop, and Queen. Does anyone have any suggestions?
You could use bit values to represent direction of moves, such as
CPP / C++ / C Code:
#define  ACROSS  1
#define  DIAG    2
#define  MANY    4
#define  SINGLE  8

int RookMove    = ACROSS | MANY;
int BishopMove  = DIAG | MANY;
int QueenMove   = ACROSS | DIAG | MANY;
int KingMove    = ACROSS | DIAG | SINGLE;
etc...
Then in your routine, test the movement value of the piece and the new position to see it it is legal.
__________________

Age is unimportant -- except in cheese
  #5  
Old 26-May-2004, 22:40
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough
ok here's the run down of how moving works:
1) Chess board is an 8x8 matrix with characters representing each piece.
2) Players are asked which piece they'd like to move(Everyone already helped me check that within this forum right here
3) After it is assumed that the player is moving to a valid space and they are moving a valid character I was hoping to check the actualy move.

WaltP - your ideal seems intresting but I'm not really sure how to use it. Could you perhaps elaborate or give me a link to a tutorial that would help me out some.
  #6  
Old 27-May-2004, 23:37
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by dabigmooish
ok here's the run down of how moving works:
1) Chess board is an 8x8 matrix with characters representing each piece.
2) Players are asked which piece they'd like to move(Everyone already helped me check that within this forum right here
3) After it is assumed that the player is moving to a valid space and they are moving a valid character I was hoping to check the actualy move.

WaltP - your ideal seems intresting but I'm not really sure how to use it. Could you perhaps elaborate or give me a link to a tutorial that would help me out some.

If you define a structure to define a piece's color, direction of movement, length of movement, and anything else specific to a piece, then create an array of this structure defining all 32 pieces, you can write one relatively simple routine to test if a move is legal. You won't have to do a lot of nested if's
CPP / C++ / C Code:
if (bishop)
else
if (queen)
else
if (rook)
...
All you need for most pieces is to decide what direction the move is and see if that direction is in the legal list.
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pls help in this coding. harsha C++ Forum 5 08-Apr-2004 20:48
coding a sentinel controlled loop tommy69 C++ Forum 2 10-Mar-2004 14:52
coding a word with a givin factor funnyf C++ Forum 2 13-Jan-2004 08:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:00.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.