Woo wee… It’s been a long time since my last update, but that’s not without great news. As mentioned in my previous post, I am now able to make betas and send them through TestFlight. With this newfound inspiration, the game right now sits out a very nice polished state for the game mechanics up to the Algebra mode. But lets see what I have done since March 8th all the way to now.

## Division Problem Generation

Because I decided to go with more than just a a/b=c problem generation for division I had a lot of logic to test to make sure that integer division was happening and that the problems were not too hard. Before we dive into what I did for the code these were the six types of problems I chose to incorporate.

**** EXAMPLES ** **
1.) a/x=b
2.) x/a=b
3.) x/(a/b)=c
4.) (x/a)/b=c
5.) a/(x/b)=c
6.) (a/x)/b=c

Implementing problems 1.) and 2.) was quite straightforward as you just have think of it as “a/b=c” where b is between 1-12 and then you can multiply a by a random number 1-12 so it will always be integer division. A good by-product of also having all the numbers is that you can replace a or b with x and then serve it to the player. When I refactor my code I will probably implement this method as the current one I am using for division is less elegant.

Things start to get hairy when we move onto problems 3.) through 6.) as we have to check for three things. First, order of operations. Second, integer division. Third, a reasonable problem to solve (no numbers outside the 12-times table. With all three of these parameters in mind 6.) was a logic nightmare. To ensure that all 3 conditions were meant I used a while loop that would check for the following and would run if it was true.

```
6.) (a/x)/b=c
(x == 1 || distributionP || x > 12 || b > 12 || x == 0 || a / x == 0 || (a % x) != 0 || a / x > 12 || (a / x) % b != 0 || a % (c * b) != 0)
x == 1 -> this would be essentially the same as a/b which is boring.
distributionP -> we'll discuss this later.
x > 12 or b > 12 or a / x > 12 -> This is to make sure we are doing division within the 12-times table
x == 0 -> anything divided by 0 doesn't end well.
a/x == 0 -> this should not be possible as 0 is not an input but just in case as x could be anthing and still be true.
(a % x) != 0 or (a / x) % b != 0 or a % (c * b)-> using the modulo operator (%) we can make sure the result is an integer after dividing/
```

You might be wondering what is that distribution P about? This is mainly used for something like 5.) but it helps distribute x to be more uniform in its spread.

## Exponent Problem Generation

After refactoring the code It was pretty simple to get through this one. The only major thing is that when you have x to and even power the user should be able to input a negative answer so you have to account for that. Besides that it is pretty simple and I was able to use the âˆš instead of the 1/2 which I enjoy. I might look into buying this asset; however, I need to make sure that it applies the fonts properly before a drop a pretty dime.

## PEMDAS Problem Generation

This is where things get fun. In the arithmetic mode the code was long and arduous for generating PEMDAS problems. I wanted to have a more simple approach. After searching and and asking I got my answer. Now I think ideally I would use an Abstract Syntax Tree (AST) but I am not sure how to code that and then use it in my project, this means I must look for a simpler solution. Stack Overflow for once finally helped with this amazing answer. My computer science knowledge is still limited so initially it was a bit confusing what was going on but basically you have a class that has a constructor which takes in a function and a symbol. So I then can initialize operations with a lambda expression and the corresponding symbol. If that did not make sense let me break it down.

`private Operator Add = new Operator((a, b) => (a + b), "+");`

**private** – This is a variable global variable only accessed within the current script. (not too important

**Operator** – This is setting the type of the variable to be a class member so it can use the Operator’s constructor and methods (to see the class itself check the post.)

**Add** – This is the name of the operation (could be “jshk” but Add is a lot more descriptive.)

**new Operator(**paramter a**, **parameter b**);** – We’ll look at parameter a and b below but this is just initiating Add to be of the class Operator (typical object-orientated programming stuff.)

**(a, b) => (a + b) **aka paramter a – This is called a lambda expression. You have a “function” that has the inputs of a and b and then using the => you will get the output or returned value of a+b). So a simpler way to think of it as the function below. You might be interested why the Operator class is Func<int, int, int> that’s because the first two ints are the inputs and the last int is the output.

`public void functionName(a,b) { return a+b; }`

**“+”** aka parameter b – this is just a string that represents the operation

Now why all of this stuff? Well because I can create a bunch of different operations and then just create a variable of type Operator like a so:

```
Operator op1 = Add;
op1.Calculate(x,y); // does x+y and returns the result
op1.Symbol; // returns the symbol's string
```

Because of this I can really simpfly the way I do boolean logic because If I randomly generator a PEMDAS problem like a+b/c=d I can see if the second operation is division by checking to see of op1.Symbol.Equals(“/”) and if it does I can make run additional code to ensure I have integer division.

With all this said how was it applied? Well, I have a set of equations I wanted to use:

```
1.) a[]b[]c=d
2.) (a[]b)[]c OR a[](b[]c)
3.) (a[]b)Â²[]c=d OR a[](b[]c)Â²= d
4.) âˆš(a[]b)[]c=d OR a[]âˆš(b[]c)=d
// [] are replaced by +, -, *, or /
```

From here I have code that does the proper testing to make sure items that were addressed in the division section happen. The notable difference is this is when I implemented the idea of solving for abc and then just replacing once of those with an x.

## Coding is done.

Many infinite loops later, I finally finished coding an refined all the small issues. I shifted my gears on making the testing and gameplay a little better. I first did this by implementing a button where the user can increase or decrease their level so they can experience different problems if they want.

I also added a background song. This song was made in beepbox.co and I absolutely love it. I may want to go back and make it loop or at least end a little smoother but for now, I added it to unity with the assistance of this forum post and it works perfectly!

I want to create about 5-11 more songs so I can have a soundtrack for the game; however, for now this song will do.

## Where we are at

And that’s it. After about 2-3 weeks you can now join the beta and play this pretty good version by going to https://onebyone.bricepbrown.com/. If you are interested in what the gameplay is like here you go: