How to develop recursive function to interesting game . Recursive Challenge - c++

i am developing a kid´s game.
It consists in
3 Tags
6 sacks
Each sack has one secret fruit inside:Bananas or Tomatoes
The first step is to reveal one sack, for example imagine we reveal sack 2 and it is a T(Tomato)
Now the rule is that you have to assign Tags to Sacks , following the rule that no of to sacks has above a correct Tag
So we start to assign tags to sacks.
And finally:
I don´t know how to develop a recursive function that checks the validity of each movement. I have tried a lot of functions but it ´s becoming impossible.
I think the best option is to create
Recursive function
Checks if any other Tag could be a possible solution of the sacks revealed.If it finds another tag that fit in the sacks (with future solution possible of course) is Game Over.
Which is the pseudo code of this function?Or you can imagine another way to develop this code??
I am really stuck and I ask here because you are awesome
Don´t forget that the game is looking for any other possible movement to return game over, he wants you to fail!

Here I've got one possible solution without recursion. I know that you requested pseudo code, but I did it in JAVA just to make sure that is working. At least it will give you another direction where to look at.
Let's assume that you have an array that represent all your possible combinations, e.g:
"00" => Apple-Apple
"01" => Apple-Banana
"10" => Banana-Apple
"11" => Banana-Banana
So, let's do the validation to find out if the MOVEMENT is valid.
public class TestCode {
public static String[] stuff = new String[] { "00", "01", "10", "11" };
public static Boolean isMySearchValid = false;
public static void main(String[] args) {
String first = "01"; // my first guess was "01" which is Apple-Banana
isMySearchValid = isValid(first, "11"); // find out if 10 is valid and
// also has not been taken
// already
System.out.println(isMySearchValid);
}
public static Boolean isValid(final String firstGuess, final String newGuess) {
Boolean response = false;
if (firstGuess == newGuess) {
response = false; // Game Over, because the newGuess was already
// taken
//System.out.println(response + " 1");
} else {
for (int i = 0; i < stuff.length; i++) {
if (!stuff[i].contains(firstGuess)) {
if (stuff[i].contains(newGuess)) {
response = true;
System.out.println("VALID: because was found available in emelement : " + i);
break;
}
}
}
}
return response;
}
}
2nd Approach: (Pseudo Code)
#define VALID_MOVE = 1;
#define TAG_ALREADY_EXIST = 2;
#define NOT_FOUND_OR_NOT_VALID = 3;
int isTagValid(sring[] ArrayOfTags, string tagToFind) {
string[] tempArray = NULL;
int response;
if(tempArray != NULL) {
foreach(string str in tempArray) {
if (str == tagToFind) {
response = TAG_ALREADY_EXIST;
}
}
} else {
foreach(string str in ArrayOfTags) {
if (str == tagToFind) {
tempArray.add(tagToFind);
response = VALID_MOVE;
} else {
response = NOT_FOUND_OR_NOT_VALID;
}
}
}
return response;
}

Notice that if you proposes another card to a sack as a gameover situation, the next movements should be able to solve the game succesfully. Is not enough to check the validity of 1 movement, you need to check until the game ends.
You assign the 3rd card (Banana| Tomato) to the 3-4 sacks cause is the only one which satisfies the 2 rules (fruits are the same in sacks/card & card not above sacks).L
Later, we do another move .We move the 1st card (Tomato| Tomato to the 3rd sack because we have to satisfy that the rule of "correct card is never above sacks". If the algorithm is one step only checking, it will says that the correct one is the other possibility=>card 2 (Banana|Banana), so it will show us game over. But what the algorithm doesn´t know is that the game became unsolvable because we have a card above the only sack pending to solve (Tomato|Tomato)

I'm going to assume that you have a fixed, small set of fruits, each with an associated id. The simplest way to implement this would be an enum:
enum Fruit {
APPLE,
PEAR,
BANANA
};
This way, APPLE has the value 0, PEAR is 1, and BANANA is 2. Now you can represent any sack pair or card by an array telling how many occurrences there is of each fruit (each element would tell the number of occurrences of the fruit that corresponds to the index). For example, a card with two apples would be {2, 0, 0}, and a sack pair with apples and bananas would be {1, 0, 1}. For each sack pair, you would also keep track of the "visible" fruits: if the aforementioned sack pair hasn't been opened, we have {0, 0, 0}, and when we have only revealed the apples, we would have {1, 0, 0}.
Now, all you need to do to figure out whether a given card is compatible with what we know about a given sack pair is to check each pair of elements and see if all elements from the sack pair's array is less than or equal to the corresponding element of the card's array. No recursion needed:
bool isCompatible(const vector<int> & card, const vector<int> & sack) {
for (int i = 0; i < card.size(); i++) {
if (card[i] < sack[i])
return false;
}
return true;
}
bool isLegalMove(const vector<int> & movedCard, const vector<vector<int> > & otherCards, const vector<int> & sack) {
if (!isCompatible(movedCard, sack))
return false;
for (int i = 0; i < otherCards.size(); i++) {
if (isCompatible(otherCards[i], sack))
return false;
}
return true;
}
Edit: I still don't quite understand the mechanics of your game, but here's the general approach for simulating possible game moves until the game ends. The code assumes that any move will always make the game progress closer to the end, i.e. that it's not possible to go around in circles (if it were, you'd need additional code to keep track of which game states you've tried out).
I'm assuming that all of your game state is wrapped up in a class called GameState, and that a move can be represented by Move. In your case, you might have two subclasses of Move, namely OpenSack (containing the sack index) and MoveCard (containing the original and final positions of the card being moved). You need a function vector<Move *> generateMoves(GameState &) that can generate the moves that are possible in a given game state (note that if the game state is a "game over", this function should return an empty vector). Move needs an abstract function GameState perform(const GameState &), to be implemented by each subclass, that will actually perform the move and create a new GameState (rather than modifying the existing state) that represents the game state after the move. (In a game with a larger state, it would be better to actually modify the state, and to have a reverse() method that would undo the effects of a move.) Then, the simulation can be implemented like this:
bool isSolvable(const GameState & currentState) {
if (currentState.isValidFinalState())
return true;
vector<Move *> moves = generateMoves(currentState);
for (int i = 0; i < moves.size(); i++) {
GameState stateAfterMove = moves[i]->perform(currentState);
if (isSolvable(stateAfterMove))
return true;
}
return false;
}
This will play out all possible moves (this is feasible only because it's such a "small" game), and if any sequence of moves leads to a valid solution, the function will return true.

Related

Minor bug in C++ dfs question in a big test case

I am solving a question on leetcode, my answer passed 123 test cases and failed on one. I can't figure out my problem because the test case is large and my solution works with every small testcase I could think of. The discussion section of leetcode wasn't helpful so I thought id try here.
question is: "You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water.
Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).
The island doesn't have "lakes" (water inside that isn't connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island."
example test case: [[0,1,0,0],
[1,1,1,0],
[0,1,0,0],
[1,1,0,0]]
Output: 16
https://leetcode.com/problems/island-perimeter/
my solution
class Solution {
public:
bool dfs(unordered_set<string> & set, vector<vector<int>> &grid, int x,int y, int& count)
{
if(x>=grid.size()||y>=grid[0].size()||y<0||x<0)
{
return false; // false means current coordinate is not an island piece
}
string loco=to_string(x)+to_string(y);
if(grid[x][y]==0)
return false;
if(set.find(loco)!=set.end())
{
return true;
}
set.insert(loco); //insert island piece to visited pieces
int temp=4-(dfs(set,grid,x+1,y,count)+dfs(set,grid,x-1,y,count)+dfs(set,grid,x,y+1,count)+dfs(set,grid,x,y-1,count)); //subtract the number of adjecent island pieces
count+=temp;
return true;
}
int islandPerimeter(vector<vector<int>>& grid) {
unordered_set<string>set;
int count=0;
for(int i=0 ;i <grid.size();i++)
{
for(int j=0;j<grid[0].size();j++)
{
if(grid[i][j]==1) //find the first piece of island and run DFS
{
dfs(set,grid,i,j,count);
return count;
}
}
}
return count;
}
};
I have checked the discussion section of leetcode but most of the solutions were iterative and didn't use DFS like i did. I am trying to understand what the problem is with my solution.
The testcase that failed is :
[[0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,0,1,1,0],
[0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0,1,0],
[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1,0],
[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0],
[1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
[1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0],
[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0],
[0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0],
[0,0,1,1,1,0,1,1,1,1,1,1,0,0,1,1,0,0,0,0],
[0,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0],[0,0,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0]]
expected output=128
my output= 125
You are using string loco=to_string(x)+to_string(y); as the key for your std::set. Clearly, if x = 11 and y = 1 then the key is 111, just as when x = 1 and y = 11, which can break your algorithm.
Using a std::string as the set key is an unusual choice in the first place. I would recommend using std::pair<int, int> instead. Using your own type dedicated for this purpose (struct Coordinate { int x, y; };) would be even clearer but would need some additional boilerplate (namely operator<) to work with std::set, whereas std::pair has this out-of-the-box.

How to compare many booleans to pass through specific outputs? C++ for UE4

I myself am not a programmer, but I have a programmer friend who is trying to help me with a certain task in Unreal Engine 4, and I was hoping to find some advice here to pass on to him.
What we are trying to make is a 'Node' in UE4 that can take in many boolean values (20+), and pass out specific values, or rather to pass through the event chain/line.
For example, I could have 6 booleans coming into the node, and I would want one of the outputs to pass through if boolean 2 and 4 were true, 1 was false, and the rest aren't looked at (essentially N/A). I made a quick image below to showcase what it would look like.
Example Of What Node would look like
My friend says he is not sure how such a node could be accomplished in C++, so I am hoping someone here can help give us a nudge in the right direction. Otherwise, I'll be stuck messing with branch nodes, and nodes, or nodes, and the like till my ears bleed and my project looks like a bowl of spaghetti.
Thanks for the suggestion, but I feel that that implementation is a bit too simple for what I am needing.
Hhhmmm, maybe I can explain my thoughts to the logic of it. Essentially, have the incoming boolean values into the node be made into an array of integers(or floats, dont know the difference between them really), with True = 1, and False = 2. The number of inputs to the array node can be determined by the number of inputs into the main Node.
Then, based on the number of inputs into the main Node, you can that same number of options per each event out pin on the main Node. Each option would have 3 check boxes. Checking the first box would output a 1 for True, second box would output 2 for False, and third box would output 3 for Dont Check.
These outputs could then be made into an array themselves. And then you would just have to compare the two arrays to see if they match, and anywhere there is a 3 value in the second array, that would output an 'is matching' regardless of what it is being compared to.
I just don't know actual coding, so I need a bit of help to try and explain this line of logic to my buddy, in terms of code.
Based on the information:
std::vector<int> input_vector; //the index will represent sequence and value will represent state
for(int i=0; i<node_size; i++)
{
input_vector.push_back(state); //you will push state=1 or state=2 here
}
std::vector<int> node_vector;
bool flag = true;
for(int case_no=0; case_no<cases;case_no++)
{
//checking node_vector with input_vector
for(int i=0; i<node_size; i++)
{
int choice;
std::cin >> choice; //either 1 or 2 or 3
node_vector.push_back(choice);
}
for(int i=0; i<node_size; i++)
{
if(node_vector[i]==3)
continue;
else if(node_vector[i]==input_vector[i])
continue;
else
{
flag = false;
break;
}
}
if(flag==true)
break;
else
continue;
}
if(flag)
std::cout << "Matched";
else
std::cout << "Not Matched";

Crash in std::sort - sorting without strict weak ordering

I'm trying to sort a vector of items. As mentioned in the code comments, the ordering should be:
Participants with more action points (mAp) go first. When there is a tie, participants with the same disposition (mDisposition) as the initiator of the battle (mBattleInitiator) go first.
The following code (simplified example) crashes on macOS, presumably due to my sort implementation being incorrect:
#include <QtCore>
class AiComponent
{
public:
enum Disposition {
Friendly,
Hostile
};
AiComponent(Disposition disposition) : mDisposition(disposition) {}
~AiComponent() { qDebug() << "Destroying AiComponent"; }
Disposition mDisposition;
};
class BattleManager
{
public:
BattleManager() : mBattleInitiator(AiComponent::Hostile) {}
class Turn {
public:
Turn() : mAp(1) {}
Turn(QSharedPointer<AiComponent> aiComponent) :
mAiComponent(aiComponent),
mAp(1)
{
}
Turn(const Turn &rhs) :
mAiComponent(rhs.mAiComponent),
mAp(1)
{
}
QSharedPointer<AiComponent> mAiComponent;
int mAp;
};
void addToTurnQueue(QSet<QSharedPointer<AiComponent>> aiComponents);
AiComponent::Disposition mBattleInitiator;
QVector<Turn> mTurnQueue;
Turn mActive;
};
void BattleManager::addToTurnQueue(QSet<QSharedPointer<AiComponent> > aiComponents)
{
foreach (auto aiComponent, aiComponents) {
mTurnQueue.append(Turn(aiComponent));
}
// Sort the participants so that ones with more action points (mAp) go first.
// When there is a tie, participants with the same disposition (mDisposition)
// as the initiator of the battle (mBattleInitiator) go first.
std::sort(mTurnQueue.begin(), mTurnQueue.end(), [=](const Turn &a, const Turn &b) {
if (a.mAp > b.mAp)
return true;
if (a.mAp < b.mAp)
return false;
// At this point, a.mAp is equal to b.mAp, so we must resolve the tie
// based on mDisposition.
if (a.mAiComponent->mDisposition == mBattleInitiator)
return true;
if (b.mAiComponent->mDisposition == mBattleInitiator)
return false;
return false;
});
}
int main(int /*argc*/, char */*argv*/[])
{
BattleManager battleManager;
for (int i = 0; i < 20; ++i) {
qDebug() << "iteration" << i;
QSet<QSharedPointer<AiComponent>> participants;
AiComponent::Disposition disposition = i % 2 == 0 ? AiComponent::Hostile : AiComponent::Friendly;
QSharedPointer<AiComponent> ai(new AiComponent(disposition));
participants.insert(ai);
battleManager.addToTurnQueue(participants);
}
// This should print (1 1), (1 1), ... (1 0), (1 0)
foreach (auto turn, battleManager.mTurnQueue) {
qDebug() << "(" << turn.mAp << turn.mAiComponent->mDisposition << ")";
}
return 0;
}
I've looked into other answers on the topic. Most of them just say "implement it as a > b", which won't work in my case. There are a few that seem relevant but don't help me:
https://stackoverflow.com/a/16824720/904422 - says that other standard algorithms will work but doesn't mention any concrete examples
https://stackoverflow.com/a/33508373/904422 - confusing, seems like overkill
What is the simplest way to achieve what I'm after?
The reason for the crash hasn't been explained yet. Most implementations of std::sort are based on quick sort, specifically Hoare partition scheme, which scans an array from left towards the right as long as element values < pivot values, and scans the array from right towards the left as long as element values > pivot values. These scans are counting on the fact that finding an element value = pivot value will stop a scan, so there's no check for scanning beyond the boundaries of an array. If the user supplied less than compare function returns true in the case of equal elements, then either of the scans may go beyond the array boundaries and cause a crash.
In the case of a debug build, testing of the user compare function may be done to ensure that the compare is less than and not less than or equal, but for a release build, the goal is speed, so these checks are not performed.
I'll just go off of the comment in your code and explain what's wrong with it (if anything), and how you would fix it.
// Sort the participants so that ones with more action points (mAp) go first.
Good so far
// When there is a tie, participants with the same disposition (mDisposition) as the initiator of the battle (mBattleInitiator) go first.
What if both participants have the same disposition as the initiator? Even if you can guarantee that no 2 elements will satisfy this condition, the sort algorithm is allowed to compare an element against itself. This test would return true in that case, violating one of the conditions of a strict-weak ordering, which is that an element must compare equal to itself (i.e. compare(a,a) must always be false).
Perhaps instead you want to say that if a has the same disposition as the initiator, and b does not, then a should be considered less than b. This can be encoded as:
return dispositionOfA == mBattleInitiator && dispsitionOfB != mBattleInitiator;
So your full test would look like this:
if (a.mAp > b.mAp)
return true;
if (a.mAp < b.mAp)
return false;
return a.mAiComponent->mDisposition == mBattleInitiator &&
b.mAiComponent->mDisposition != mBattleInitiator;

Inserting an object from a derived class into another instance of said object (using the vector.insert function) C++

I am currently working through code which has a Road class. This has a vector of lanes and includes a lane class. The lane class has a vector of vehicles and each vehicle has its derived classes (Car, Motorcycle, Lorry).
I would like a vehicle to be able to assess whether it can move into another lane, i.e. be inserted into another lane's vector of vehicles, safely (a car requires some safe distance, so I have already implemented how a vehicle knows if it is clear to switch lanes).
void Road::Simulate(double time)
{
for (unsigned int iLane = 0; iLane < getNLanes()-1; iLane++)
{
for (unsigned int iV = 0; iV < getCurrentLane(iLane)->getNVehiclesinLane(); iV++)
{
std::cout<< " AllowedOvertake TEST "<< getCurrentLane(iLane+1)->allowedOvertake(getCurrentLane(iLane)->getCurrentVehicle(iV)->getPosition(), getCurrentLane(iLane)->getCurrentVehicle(iV)->getMinDistance())<<std::endl;
getCurrentLane(iLane+1)->setCanOvertake(allowedOvertake(getCurrentLane(iLane)->getCurrentVehicle(iV)->getPosition(), getCurrentLane(iLane)->getCurrentVehicle(iV)->getMinDistance()));
if (getCurrentLane(iLane+1)->getCanOvertake() == true)
{
getCurrentLane(iLane+1)->insertVehicle(getCurrentLane(iLane)->getCurrentVehicle(iV), 0);
delete getCurrentLane(iLane)->getCurrentVehicle(iV);
}
}
}
for (unsigned int iLane = 0; iLane < getNLanes(); iLane++)
{
getCurrentLane(iLane)->Simulate(time);
}
}
I loop over all the present lanes, except the last one as any vehicle in this lane cannot overtake. After looping over the vehicles contained in each lane, I have a function which returns a Boolean which confirms whether an overtake scenario can be executed. This is done in allowedOvertake(). If this returns true, I implement an insert function.
My issue/question: How can I make this ideology work, and whether it is sensible to have these setCanOvertake() and getCanOvertake() functions.
One possible solution could be to just pushback a new vehicle into the intended lane, but with the appropriate positions, velocities etc. However, I am not sure how to ensure that the vehicle being entered has the same type (Car, Lorry...) too.
Currently, I do not get any build errors if I exclude the insertVehicle() function, and I have vehicle motion being drawn using QPainter. However, with the insertVehicle() function, I do not get any build errors but I do get a crash once I run the project.
Any help would be appreciated, and apologies for any coding errors (I'm a keen, but very inexperienced C++ user).
For reference, I have the above functions' definitions as follows
bool Lane::allowedOvertake(double pos, double mindist)
{
for (unsigned int iV = 0; iV < getNVehiclesinLane() - 1; iV++)
{
if ((fVehicles[iV]->getPosition() > pos - mindist)// If inside rear safety distance.
|| fVehicles[iV]->getPosition() < pos + mindist)// If inside front safety distance.
{}//continue
else {return false;}
}
return true;
}
//IN Lane.h
bool getCanOvertake() const{return FREE_LANE_OVERTAKE;}
//IN Lane.h
void setCanOvertake(bool overtake = true){FREE_LANE_OVERTAKE = overtake;}
Apologies, I was under the impression I had referenced my insertVehicle() function definition.
void Lane::insertVehicle(Vehicle*v, int ielement) {
Vehicle* vins = new Vehicle(v->getPosition(), v->getVelocity(), v->getAcceleration());
for (unsigned int iDist = 0; iDist < fVehicles.size()+1; iDist++){fVehicles.insert(fVehicles.begin() + (ielement+1), vins);}
}

C++ do while loop

I have a vector holding 10 items (all of the same class for simplicity call it 'a'). What I want to do is to check that 'A' isn't either a) hiding the walls or b) hiding another 'A'. I have a collisions function that does this.
The idea is simply to have this looping class go though and move 'A' to the next position, if that potion is causing a collision then it needs to give itself a new random position on the screen. Because the screen is small, there is a good chance that the element will be put onto of another one (or on top of the wall etc). The logic of the code works well in my head - but debugging the code the object just gets stuck in the loop, and stay in the same position. 'A' is supposed to move about the screen, but it stays still!
When I comment out the Do while loop, and move the 'MoveObject()' Function up the code works perfectly the 'A's are moving about the screen. It is just when I try and add the extra functionality to it is when it doesn't work.
void Board::Loop(void){
//Display the postion of that Element.
for (unsigned int i = 0; i <= 10; ++i){
do {
if (checkCollisions(i)==true){
moveObject(i);
}
else{
objects[i]->ResetPostion();
}
}
while (checkCollisions(i) == false);
objects[i]->SetPosition(objects[i]->getXDir(),objects[i]->getYDir());
}
}
The class below is the collision detection. This I will expand later.
bool Board::checkCollisions(int index){
char boundry = map[objects[index]->getXDir()][objects[index]->getYDir()];
//There has been no collisions - therefore don't change anything
if(boundry == SYMBOL_EMPTY){
return false;
}
else{
return true;
}
}
Any help would be much appreciated. I will buy you a virtual beer :-)
Thanks
Edit:
ResetPostion -> this will give the element A a random position on the screen
moveObject -> this will look at the direction of the object and adjust the x and Y cord's appropriately.
I guess you need: do { ...
... } while (checkCollisions(i));
Also, if you have 10 elements, then i = 0; i < 10; i++
And btw. don't write if (something == true), simply if (something) or if (!something)
for (unsigned int i = 0; i <= 10; ++i){
is wrong because that's a loop for eleven items, use
for (unsigned int i = 0; i < 10; ++i){
instead.
You don't define what 'doesn't work' means, so that's all the help I can give for now.
There seems to be a lot of confusion here over basic language structure and logic flow. Writing a few very simple test apps that exercise different language features will probably help you a lot. (So will a step-thru debugger, if you have one)
do/while() is a fairly advanced feature that some people spend whole careers never using, see: do...while vs while
I recommend getting a solid foundation with while and if/else before even using for. Your first look at do should be when you've just finished a while or for loop and realize you could save a mountain of duplicate initialization code if you just changed the order of execution a bit. (Personally I don't even use do for that any more, I just use an iterator with while(true)/break since it lets me pre and post code all within a single loop)
I think this simplifies what you're trying to accomplish:
void Board::Loop(void) {
//Display the postion of that Element.
for (unsigned int i = 0; i < 10; ++i) {
while(IsGoingToCollide(i)) //check is first, do while doesn't make sense
objects[i]->ResetPosition();
moveObject(i); //same as ->SetPosition(XDir, YDir)?
//either explain difference or remove one or the other
}
}
This function name seems ambiguous to me:
bool Board::checkCollisions(int index) {
I'd recommend changing it to:
// returns true if moving to next position (based on inertia) will
// cause overlap with any other object's or structure's current location
bool Board::IsGoingToCollide(int index) {
In contrast checkCollisions() could also mean:
// returns true if there is no overlap between this object's
// current location and any other object's or structure's current location
bool Board::DidntCollide(int index) {
Final note: Double check that ->ResetPosition() puts things inside the boundaries.