Hello Peter87,
Thank you for your response.
What you have described makes good sense, and so is pretty much what I'm looking for.
I shall update my code and see if I can make it work - considering I'm not the most experienced user. I shall post my updated code here when I'm finished so others can check to see if all code works accordingly.
Because I'm to produce a "simplified" version of backgammon, essentially, as part of my assignment, and as recommended by my lecturer, the pieces that move are those furthest from the end position. Is there any particular code you can suggest for me to calculate the furthest position on the board?
For instance, RED starts at Pieces[0][0] on the board (BLACK at Pieces[1][23]). At Pieces[0][0], 5 pieces will be held here at the start of the game. All these pieces will be moved until none are left held in this position, after which I need to find the next piece in the array furthest from the end position and move this piece up the board according to the dice value.
This is what I'm thinking:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
int pos = 0;
bool found = false;
do
{
if (Pieces[RED][pos] > 0)
{
found = true;
}
else
{
pos++;
}
} while (pos < Pieces[RED][23] && !found);
|
Any ideas here?
One other issue I have now, after working from what you have explained above, is the output of the pieces.
I wish to have a function that loops through the entire array
Pieces[2][24]
and updates the location of all pieces on the board, each time the dice is thrown.
Some code i have generated below to give a rough idea (does not work):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// Draw the RED Pieces
for (int i = 0; i < 24; i++) // Number of triangles on board (24 in total)
{
// Checks value at each triangle, for instance: [0][0] is first triangle, [0][1] is second etc...
if (Pieces[0][i] > 0) // If value at index greater than zero, move to "for" loop below and display pieces
{
double X1 = 12.5, Y1 = 1.5; // 'x' and 'y' coordinates of starting position for RED pieces
for (int j = 0; j < Pieces[0][i]; j++) // Displays the number of pieces at index on trianlge
{
// 'x' and 'y' coordinates need to update once pieces for first triangle are displayed
// Unsure how to do this???
cwin << BrushColour(204, 50, 50) << PenColour(204, 50, 50) << PenWidth() << Circle(Point(X1, Y1), 0.45);
}
}
}
|
Ideas here would be appreciated.
Once again, thanks for your response - greatly appreciated.
Bevan