Page 1 of 6

my solutions

Posted: June 7th, 2018, 8:37 am
by randomGuy
I'm currently on Intermediate C++ Game Programming and Im really enjoying it so
I'll post some of my own solutions for homework here, before watching chili's solution.
Would love to hear anyone's feedback.

Here is my solution for |Homework 5|.

https://imgur.com/a/O7eDMuH

Re: my solutions

Posted: June 7th, 2018, 8:52 am
by randomGuy
The homework was about dynamic allocation of the memefield so first I changed filed[] to field*. I then moved most of the stuff from the constructor of memefield to function called setField which allocates new array on the heap and passes it's address to *field. Is there going to be any memory leakage in my solution?

Re: my solutions

Posted: June 7th, 2018, 10:33 am
by chili
Seems good, except you're not freeing the memory when the game is destroyed (this tutorial is before destructors if I recall correctly, so you're okay not implementing a destructor). You'll learn a lot more about memory leaks in the next vidja ;)

Re: my solutions

Posted: June 7th, 2018, 1:38 pm
by randomGuy
If we dynamically alocate new object and this object has member variables which are not created with the 'new operator' like 'int width' and 'int height', are these member variables stored in the stack or they are stored in the block of memory allocated for the object ?

Re: my solutions

Posted: June 11th, 2018, 12:57 am
by chili
if you new an object up, ALL members are stored on the newed block on the heap.

a class has int x,int y,int* p

p is set to new int[x*y] in ctor

you new an object

x y p are all stored in the heap object of the new

the target of p is stored in a different heap object

Re: my solutions

Posted: June 11th, 2018, 4:21 am
by randomGuy
Makes sense now, thanks.

On Homework 6 where we have to implement a stack with linked lists,
I've solved all tests and had no memory leaks but my solution is a mess compared to yours which is so elegant and simple using recursion.

You've put a lot of thought in these challenges and I really appreciate them.

Re: my solutions

Posted: June 11th, 2018, 8:28 am
by chili
Dude, I'm glad you appreciate them.

I put extra effort into the I6 homework, hearing that makes it worth the while :)

Re: my solutions

Posted: June 16th, 2018, 1:07 pm
by randomGuy
On your word guessing game tutorial you mention something about a bot, but I can't find anything on your github. Very interested to see how it is implemented and how fast will it find the word.

Re: my solutions

Posted: June 17th, 2018, 1:55 pm
by chili
Yeah, the bot ain't on the github. Also, it's written in C#. I might be using a C# Dictionary for the lookup (basically a hash table I believe, C++ equivalent is unordered_map)

Re: my solutions

Posted: June 17th, 2018, 5:01 pm
by Slidy
Some extremely talented hacker also made a solver for the bot, no clue how: https://i.imgur.com/eEjjUGU.gifv