UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Problem with the word game challenge

Forums > 100 Days of SwiftUI

Hello, I have already finished the Word Scramble challenge, but like with all challenges here, I create apps with my own twist. I have totally changed the game mechanics, ETC, but my problem doesn't concern it. One of the twists I applied is that I have loaded my own databse of polish words, which contains over 4 MLN entries which calculated to 60 M worth of data. When I loaded them normally, like shown by Paul, straight in my initializeGame() function, all worked fine, but when I was restarting the game, the file was reloaded which, of course was useless. So then I recalled that maybe, I could use classes to get the same result (I am learning Swift only at this website so I have no other knowledge). So I have created a class (DBManager) with a String array property of name “words” and I have loaded the file in the initializer of that class. Then, when I Applied that class in my struct, like private let manager = DBManager() and rewritten the logic so that the game used the GetRandomWord() method from my class it compiled normally, however now it doesn’t load and my UI is never shown. What can be wrong? P.S. I am blind so hence I have to skip more advanced animations, my goal is to get this game to a state where I can publish it to AppStore, so any help is appreciated haha.

2      

It is difficult to try to give you more specific help without some sample of your modified code.

However, one idea would be to initialise the database, or a static set, when the app starts WordScrambleApp.swift, not when you use initializeGame().

Then in initializeGame() just access the word database / set, as needed.

2      

@Nuno has a verbose problem:

I have loaded my own database of Polish words containing over 4 million entries

This number is hard to believe.

An article in Wikipedia reports only 578,000 English words in the authoritative English dictionary. I have zero knowledge of the Polish language, so your count may include past and future tenses, different verb conjugations, plural and singular versions, and perhaps gender adjusted forms. I admit, I do not know. Yet, four million still seems quite high even accounting for variations.

See -> Dictionary Word Count

So I am not sure what problem you want to attack first?

Perhaps you can evaluate your word list and determine how long it takes to load the entire list? Are there better ways to optimize this list and load into your application?

You seemed to uncover a second problem, too. Your application loads the large word file, and allows the user to play a game.

If the user wishes to play another game, the large word file is reloaded. This is a structure problem.

If this is the problem you want to solve, you attack this as a logic problem. Or perhaps this is an architecture problem. Consider how you have structured your application.

In one respect, your application should load potential words into a giant, searchable array. This array is global and stays around for the entire time your application is running.

A sub section of your application is the game. At the start of each game, clear all your game's state. That is, clear the chosen word, clear the score, clear the used letters, clear the messages, clear the counters, clear everything! Clear JUST the game's state. Leave the global list of words untouched! Leave the sound effects untouched.

Then grab a word from the global word array, and copy it INTO your game structure. Start the game and allow your player to make guesses, updating states and messages along the way. When the game is over, then reset the game.

Do not reset your application! You want to keep the large word array, and only reset the game state.

Hope this helps.

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.