top of page

Decks

Starting Date: 13/02/2025

Ending Date: 18/03/2025

This blog is about creating the decks in the game including a deck pool and pile to create and draw cards.

Objective

The goal of this blog is to create decks of each type of card in the game, along with items as they will need to be inside of a inventory. There needs to be a method to obtain cards and items and during certain player behaviour will need a deck pile to draw the cards (I'm not considering adding a discard pile due to providing independent probability of each card being drawn).

​

The first objective is to create the deck with suitable capacity due to each character having unique deck capacities, this will involve creating certain amount of empty slots in order for provide suitable amount of capacity in each of the decks.

​

The second objective is to provide a method that creates cards, this will involve creating the card itself and being called by certain scripts to create the specific type of card including rarity.

​

The final objective is to create a deck pile in order for the cards to be drawn out for the player to use, this will involve making a random number generator which the number can be use to draw a specific card out of the deck.​

Techniques

Object Pooling

Object pooling is a optimisation pattern that instantiates all the objects required once which are all disabled in the hierarchy, when a method requires one of those objects the pooling will check if an object is disabled, which will then enable that object to be created in the scene.

​

I use object pooling to instantiate the resources equal to each deck capacity in the character data (scriptable object) in order to make the suitable amount of resources for each deck, the disabled cards wait until the player lands on either a card, item, lucky, market or fruit machine space that occurs to them obtaining a resource which will enable the resource object and add a suitable behaviour component to that object.

​

This pattern is very useful for performance because all the required resources are added onto scene already and there is no requirement to instantiate or even destroy objects in the board map scene, this will lead the player to have efficient performance when obtaining resources that don't impact the performance a lot.

Game Loops

Game loops are sequencing patterns that can repeat the code that is inside of the game loop multiple times until the condition is met to stop looping, meaning that I don't need to repeat writing the code and instead use a game loop to write the code once.

​

I used game loops in both creating the card and drawing cards from the deck pile:

 

Towards creating the card, I use a do-while loop which execute the code inside of the do loop once, which will check if the card is the same rarity as the parameter, then the while loop will repeat if the condition in the while loop is false, meaning that the code will always be execute at least once compare to while loops which might not loop at all.

​

Towards deck pile, I also use a do-while loop, however provided a for loop to make all the integers in a list randomise their value equal to the amount of cards in each deck, the do loop will use the for loop to randomise each integer in the list and the while loop will then check if all the values are unique, otherwise it'll repeat the loop again.

​

Game loops are very useful for me to create because this I can follow the don't repeat yourself principle which prevents me from repeating code between each other in a method, meaning that the amount of repetitive coding is reduced, which leads me to improve the performance for the players to have suitable frame rates.

Challenges

While Loop Crashes

When using while loops, the game crashes when a while loop is executed in the deck pile scripts, the issue was the fact that the while loop was constantly looping without the condition being true.

​

This is a major issue because the player won't be able to play the game by drawing cards, meaning that they can't be able to use the cards for certain situations.

​

This was fixed due to my mistake of testing the draw cards method by placing the method in an update method that constantly updates, which then instead change for an input to call the method, this was successful because I will know when needing to call to draw cards in the script will be able to draw the suitable cards, leading to the player able to draw cards when required.

Achieved

Deck Pool Complete

The deck pools were completed by using object pooling to create suitable amount of empty resource and enabling the resources when a player obtains one, add the suitable behaviour component and using game loops such as do-while to create the cards with the suitable rarity in the game.

​

This becomes effective for players to obtain new resources in the game because they will be able to store suitable items and card rarity in the game to provide odd chances on obtaining a minor to major resource, which leads to the player to be satisfied when obtaining a very rare resource.

Deck Pile Complete

The deck piles were completed by using multiple game loops to check if the integers are unique, which will cause the integer to draw the specific card from the list.

​

This becomes effective for the player to draw random cards than duplicates because the player will then have an dependent and even chance of obtaining the card they want to use on their turn, which leads to relying on chance as well as their decision to make drawing the card they want dependent based on the resource they obtain throughout the game.​

Conclusion

Overall, I have learnt a lot of using object pooling and game loops to improve the performance of the game along with reducing the amount of code to write in each of my scripts due to only needing to write the code once and provide loops to repeat the code again,

​

As a programmer reducing the amount of instantiates and destroy methods are effective because enabling and disabling the objects affects the performance less to provide better frame rates. In addition, reducing code is very useful for me since I can identify issues with smaller lines of coding in a script.

​

If a lot of objects will need to be instantiated and destroyed, then I should rely on object pooling for future project. In addition, if I need to repeat coding in a script then I should rely on game loops whether this be loops I used such as for and do while or other existing loops such as for each for lists or while to provide unique looping towards implementing a method.

bottom of page