my solutions

The Partridge Family were neither partridges nor a family. Discuss.
randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

my solutions

Post by randomGuy » June 7th, 2018, 8:37 am

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

randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

Re: my solutions

Post by randomGuy » June 7th, 2018, 8:52 am

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?

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: my solutions

Post by chili » June 7th, 2018, 10:33 am

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 ;)
Chili

randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

Re: my solutions

Post by randomGuy » June 7th, 2018, 1:38 pm

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 ?

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: my solutions

Post by chili » June 11th, 2018, 12:57 am

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
Chili

randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

Re: my solutions

Post by randomGuy » June 11th, 2018, 4:21 am

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.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: my solutions

Post by chili » June 11th, 2018, 8:28 am

Dude, I'm glad you appreciate them.

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

randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

Re: my solutions

Post by randomGuy » June 16th, 2018, 1:07 pm

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.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: my solutions

Post by chili » June 17th, 2018, 1:55 pm

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)
Chili

Slidy
Posts: 80
Joined: September 9th, 2017, 1:19 pm

Re: my solutions

Post by Slidy » June 17th, 2018, 5:01 pm

Some extremely talented hacker also made a solver for the bot, no clue how: https://i.imgur.com/eEjjUGU.gifv

Post Reply