Reversi Game - Function help


 
Thread Tools Search this Thread
Top Forums Programming Reversi Game - Function help
# 1  
Old 02-25-2008
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.
# 2  
Old 03-01-2008
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?
# 3  
Old 03-02-2008
Quote:
Originally Posted by Raffles
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Programming

Game script

Hi everyone, I need some help seriously. The game is in text mode. It will be based on questions and answers and simple commands. A menu containing options of the game including: 1-Create a new player. 2-Identify as existing player. 3-Launch a new game: this action opens a new game for an... (1 Reply)
Discussion started by: NaimZero
1 Replies

2. Programming

Tetris Game in C++

Open Source Project: https://github.com/yongye/cpp Ported from the shell: Shell (0 Replies)
Discussion started by: complex.invoke
0 Replies

3. Shell Programming and Scripting

The Game Problom

weh i type in sudo shutdown nowit dose not le me shut down can i override this with out tyoing in -h :confused: my web site in the makeing is also wantin ga gane code for unix and well as a shut domne hwlp (3 Replies)
Discussion started by: thepicoman
3 Replies

4. UNIX for Dummies Questions & Answers

Game Programming? Help!!

I am interested in learning how to write code for games. I am a C.S. student at UNO but I am in freshman classes and they are so slow. Can anyone recommend any languages to start learning first or any other ways to get started? I have Unix with Solaris in the labs at school and I also have... (4 Replies)
Discussion started by: bjm2020
4 Replies
Login or Register to Ask a Question