The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 08:39 AM
Game: Name this person reborg What's on Your Mind? 268 09-03-2007 05:47 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-25-2008
Registered User
 

Join Date: Feb 2007
Posts: 67
Reversi Game - Function help

So I am making a Reversi program, and I found that a function doesn't work correctly as it should.

Code:
int check_file(int x, int y, int xinc, int yinc, int xmax, int ymax, int xmin,
	       int ymin, char board[BOARDSIZE][BOARDSIZE], char piece, int ai)
{
	char opponent = flipped(piece);
	int valid = 0;
	int x1 = x, y1 = y;

	while (x1 < xmax || x1 > xmin || y1 < ymax || y1 > ymin) {
		if (board[y1][x1] == opponent)
			valid = 1;
		else if (board[y1][x1] == piece && valid == 1) {
			while ((y1 != y || x1 != x) && !ai)
				board[y1-=yinc][x1-=xinc] = piece;
			return 1;
		} else
			return 0;
		x1+=xinc, y1+=yinc;
	}
	return 0;
}
It works when piece is black (@), but not white (O). Since this function make little sense on it's own, I'll post the file with the other source code inside it.

LA.GG— [viewing file: reversi.tar]

All help is appreciated,
Octal.
Reply With Quote
Forum Sponsor
  #2  
Old 03-01-2008
Registered User
 

Join Date: Mar 2008
Posts: 1
Code:
while (x1 < xmax || x1 > xmin || y1 < ymax || y1 > ymin)
What if, x1 is greater than xmax and y1 is also greater than ymax (or indeed, less than ymin)?

Wouldn't your statement resolve to TRUE?
Reply With Quote
  #3  
Old 03-02-2008
Registered User
 

Join Date: Feb 2007
Posts: 67
Quote:
Originally Posted by Raffles View Post
Code:
while (x1 < xmax || x1 > xmin || y1 < ymax || y1 > ymin)
What if, x1 is greater than xmax and y1 is also greater than ymax (or indeed, less than ymin)?

Wouldn't your statement resolve to TRUE?
After trying '&&' instead of '||', I noticed that the function doesn't work correctly for black's, or white's moves.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0