Array checker game

So I have to wirte a checker game that has one of the functions that checks a checker's position on the board. I have to follow these guidelines


Your function CheckList has the prototype
bool CheckList( int inArray1[], int inArray2[], int xIndex, int yIndex);

Your function CheckList uses the pair of arrays. The pair of arrays inArray1[] and inArray2[] contain the x and y indices of some of one player’s checkers. The array inArray1[] contains the x indices and the array inArray2[] contains the y indices. The pair of arrays used as actual parameters when your program calls CheckList will be the arrays generated by CountJumps of the arrays generated by CountMove1Squares.
Your function CheckList also uses parameters xIndex and yIndex, the x and y indices of a particular checker.
Your function CheckList determines if the checker at (xIndex, yIndex) on the board is in the list of checkers described in the arrays inArray1[] and inArray2[].
a. If the checker at (xIndex, yIndex) is in the list the function returns true

b. Otherwise the function returns false


So far my code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
  bool CheckList(int inArray1[], int inArray2[], int xIndex, int yIndex)
{
	if (0 < xIndex < inArray1 &&  0 < yIndex <  inArray2)
	{
		return true;
	}

	else 
	{
		return false;
	}
}


Im getting an error that the x/yindex are incompatible with the inArray1&2. it says that operand types are incompatible ("bool" and "int*")

Thanks in advance,
Last edited on
Every comparison in C++ must be independent from another comparison.

By this I mean,
0 < xIndex < inArray1 must be
0 < xIndex && xIndex < inArray1

Edit: Oh wait... that isn't your only problem!
Even if you do (xIndex < inArray1), it still doesn't make any sense, because you're comparing an integer to an array!
Perhaps you mean to be doing "0 <= xIndex && xIndex < Length_Of_Your_inArray1"
inArray1[] has a size, but you need to pass in what the size is as a parameter, because an array doesn't know its own size (when passed into a function).
Last edited on
When you declared your array, you probably did something like this:

 
int arr[10];


In this, the size of your array is 10.

If you had done something like this,
 
int arr[] = {1, 4, 5};

The size of your array is 3.

You need to add an int parameter to your function to pass the size into.
For example,
1
2
3
4
5
6
bool foo(int inArray1[], int inArray1_size, int xIndex)
{
    if ( 0 <= xIndex && xIndex < inArray1_size)
        return true;
    return false;
}


Call it like this:
1
2
3
4
5
6
int main()
{
    int arr[10];
    int i = 3;
    bool result = foo(arr, 10, i);
}


As you can hopefully see, this makes passing in the array itself useless, because you don't use it.

You can change your function to:'
1
2
3
4
5
6
7
8
9
10
bool test(int inArray1_size, int xIndex)
{
    return (0 <= xIndex && xIndex < inArray1_size);
}
int main()
{
    int arr[10];
    int i = 3;
    bool result = test(10, i);
}


Edit: Disclaimer, I don't know if that's actually what you want your function to be doing, I'm just offering an alternative to your existing code, which doesn't make sense.
Last edited on
1
2
Your function CheckList has the prototype
bool CheckList( int inArray1[], int inArray2[], int xIndex, int yIndex);


I think the OP has to work with this and can't change it.
AFAIK checker use the same board as chess si 8 rows and 8 cols can be assumed.

@OP, can you post the complete assignmnet ?
Thomas1965, if that's true (which I agree it probably is), then OP should just "hardcode"
0 <= xIndex && xIndex < 8 && 0 <= yIndex && yIndex < 8
Ganado,
I think it's not so easy.
According to the Wiki the board has only 32 reachable squares so you would need only to check 4 squares per row
https://en.wikipedia.org/wiki/English_draughts#Sample_game
I was just going off of what OP's original code was, attempting to fix it.
But it looks like what the original post is doing does not match the description of the problem.

The actual CheckList function is supposed to search through the arrays, which I nor the OP were doing.

The issue is we don't know what the size of inArray1 or inArray2 is. I'm just going to label it as "N" for now. (Edit: Changed N to 12 because there's 12 pieces per player. I assume dead pieces will have an invalid index like -1 -1)

If my skimming of it is correct, the function should look somewhat close to this
1
2
3
4
5
6
7
8
9
bool CheckList(int inArray1[], int inArray2[], int xIndex, int yIndex)
{
	for (int i = 0; i < 12; i++) // "The pair of arrays inArray1[] and inArray2[] contain the x and y indices of some of one player’s checkers"
	{
		if (inArray1[i] == xIndex && inArray2[i] == yIndex)
			return true;
	}
	return false;
}

Last edited on
@Ganado,
somehow I can't follow you.
Since the board has 8 rows and 8 cols shouldn't you check all 64 or at least 32 reachable fields ?

I guess we have to wait for the OP to give us more information.
Since the arrays contain the indices of one player's checker pieces, there can't possibly be more than 12 per player. But yes, we have to wait for OP because the description of he gave -- "contains the x and y indices of SOME of one player's checkers" -- is ambiguous.
Last edited on
Topic archived. No new replies allowed.