So here's what I did too improve today
1. Fucked around with snek game until I came up with a way to solve
the issue of the goal spawning on top of obstacles
2. watched the tutorial on github. Understood the gist of it but will
take some practice getting used to for sure. A couple things were
unclear to me.
If I make a branch and work in it until that branch is better than
the master branch, do I now somehow promote my new branch to master?
can I make tons of branches which are all different games starting
from an empty chili framework and branch out into a bunch of games
from that one?
Tried doing the homework. Got to the point of having cloned the repo
but wasn't able to figure out how to run it.
Then I watched episode 16, finally a whole episode where everything
made sense to me!
alright then on to homework. Let's see what we gotz here.
I'll need the radius, then just make a function like the
DrawSquare function but add an if statement and if the point
I'm trying to draw is too far away from the radius then it wont get
90 minutes later I've managed to come up with over 9000 ways to
write the same thing, drawing a square each time
BUT WAIT! Chili left a hint about pythagoras which is a^2 + b^2 = c^2
so let's see what we can do....triangles...cirlces .... mathz....
So ended up cheating in the end and watched the solution.
Safe to say I wouldn't have gotten there on my own
const bool eating = ( next == goal.GetLocation() );
bool isOverlapping = false;
goal.Respawn(rng, brd, snake);
for (int i = 0; i < nObstacles; i++)
isOverlapping = isOverlapping && ( obstacles[i].GetLocation() == goal.GetLocation() );
} while (isOverlapping);
Moving the goal.Respawn call inside the 'do' loop is the only change I would have made. Since the do loop does at least one iteration before checking the condition, you can move the respawn function inside the loop and don't need it in the for loop.
Because of order of operations in C++, you don't need parentheses around your comparisons, but it might make it a little clearer and avoid misunderstandings later on if you used them, just a personal opinion though.
isOverlapping = isOverlapping && obstacles[i].GetLocation() == goal.GetLocation();
does the compiler evaluate isOverlapping && obstacles[i].GetLocation() first? OR
does the compiler evaluate obstacles[i].GetLocation() == goal.GetLocation() first?
I believe in this instance, it evaluates isOverlapping first and if it is false, the rest doesn't even matter, it just returns false and doesn't evaluate the ==.
If the operator&& was overloaded like the operator== has been, then it would evaluate both sides before determining true or false.
Just some food for thought, I want to say it's been awhile, but I have had unexpected results from not knowing in which order the conditions were evaluated.
Thanks for the help
Order of operation seems like a mindfuck