### Elixir Excerism Track - Lesson 3 "Pacman Rules"

Elixir
##### Transcript

English (Auto-generated)

Hello. Today, we are going to do the third exercise in the elixir track of exorcism. And it is the pac man rules exercise. So, I've already gone and brought the exercise onto my local machine here. And this way the code I write will be able to show up in the player for you guys to access as well. So, let's go ahead and get started. So, as always in the directory, um I have all three of the previous ones here, but we can find the rules in the Read me over here. So, let's find out what we want to do. So, in this exercise, you need to translate some rules from the classic game pacman into elixir functions. You have four rules to translate all related to game stats. So, the first one is defined if pac man eats a ghost, define the rules dot eat ghost function. That takes two arguments. If pac man has a power pellet active, and if pac man is touching a ghost and returns a boolean value, if pac man is able to eat the ghost, the function should return true. Only if pac man has a power pellet active and is touching a ghost. All right, so, we have our base setup here are based structure. So, we wanted to return true only if it has both a powerful active and is touching a ghost. We need both of these to be true for it to return True. So, what I'm gonna do is I'm going to duplicate this, Get rid of the end because I'm actually just gonna turn these into short form here and what we want want is this top one here is going to be true and true and then it will return true because it's true. If both variables are true, only if people are actively touching a ghost. So if any other case other than this it's going to return false. So we can keep the variables because it doesn't matter what it gets because if this one doesn't pass correctly it'll go onto the next one. But because we're not using these variables, let's go ahead and prefix them with an underscore here. And let's run our test to see if that passes. So all three of our eat ghost tests have correctly passed. So that one is right. We can move on to the second one. So for the second one it says define the rule score to function that to take two arguments. If pac man is touching a power pallet and if pac man is touching a dot and returns a boolean value. If pac man scored, the function should return true. If pac man is touching a power pellet or adopt so for this one it can return true if either of these are true so we can have false true, true false or true true. So we're gonna actually basically do this one but flipped. So let's go ahead and do the same things before we'll copy it up, get rid of this end and what we're gonna do is we're gonna say the only way it's gonna return false is if both are false, otherwise it's going to return true and we're gonna test on that one as well and perfect all three of our scores past there so we can go on to the lose function. So to find a pac man loses to find the the rules lose function that takes two arguments. In fact it is a power pellet active. And if pac man is touching a ghost and returns a boolean value, if pac man loses the function should return true. If pac man is touching a ghost and does not have a power pallet active, so it should only return true if it's touching a ghost but does not have a power pellet active, which means basically if this is true then this is false, return trip. Any other option should return false and let's go ahead and get rid of this end and we will go prefix these guys with underscores here the And let's give that a test and perfect all of those past. So now we can go ahead and do the win to find the rules wind function. Excuse me, that takes three arguments if pac man has eaten all of the dots. If pac man has a power pop active and if pac man is touching a ghost and returns a boolean value. If pac man wins, the function should return true. If pac man has eaten all of the dots and has not lost based on the arguments defined in part three. Alright so we want Pechman loses that obviously he doesn't win. Um But he has to also eat all the dots. So the only way for it to be stupid kate this. So the only way for him to win. As if. Mhm. He has hidden all the dots and if if he has a power pellet active but he's not touched and he touches a ghost, he'll still win because the powerball is active. So this one can be true and this one actually doesn't matter what it is. So that's an option where he can win all the doctor Eden. He has a powerful and active and is touching a ghost. So that will work because again it doesn't matter which one of these. He only he only loses if the ghost touches him without the power pellet. So we can also have where he's eating all the dots. You need to come here. Um The power pallet is not active and he's not touching a ghost. That one will also return true. Ah What other combinations here? Okay so he can lose if he has written all the dots but this is triggered so he can lose here. If he gets touched by a ghost but it's not eating the power pallet. So this one returned false. And then our only other combination would result in him not eating all the dots in which case no matter what these two are. He loses. So we can prefix these. And then also market has believe that is the only once let's walk through this again. So he has to eat all the dots and has not lost based on the arguments to find in part three. So basically he cannot be touched by a ghost without a power pellet active. And he has to eat all the dots. So he's eating all the dots. He has a parabolic active. Doesn't matter if he touches the ghost or not. He wants, he's eating all the dots. He does not have power plant active but he does not touch a ghost. He also ends, he's eating all the dots. He does not have probably not active but a dose touches him. He loses, he does not eating all the dots. And then it doesn't matter about these two because he loses because they're seeing all the dots. I think those are our only variables there. So let's go ahead and run our tests. Oh, I didn't save it. Mm hmm. Probably one file. Oh yeah that's true. I just forgot to plate the end work there. Perfect. So all of our tests have passed there and that is the solution to the pac man rules exercise. So from here we can go ahead and submit it. Um submitting your solutions. So let's go ahead and do that. Mhm. Perfect. Um Thank you. The solution is good enough to continue. Mm hmm. Oh yeah, submitted veal cli few seconds ago. Past awesome. So Mark is complete. Uh, iteration too. I must have practiced this a while ago. I haven't touched these in a long time. I probably did this before tam was assigned into his homework. Um, so we'll just do iteration to there and confirm and perfect. So that is the pac man rules one complete. And um I hope that was helpful.
42 Views 0 Likes 0 Comments

Let's tackle the packman rules lesson on Exercism. This is also homework for the Intro to Elixir Series!

##### Comment
Leave a comment (supports markdown format)