Gengo Girls #71: Some Of My Best Friends Are Books

Gengo Girls #71: Some Of My Best Friends Are Books

One rule of thumb is that if an adjective is written 100% in kanji, like 綺麗, it is probably a “na” adjective even if its last syllable is an . It’s only words like 新しい that are written with an actual that follow rules.

Of course, there are still a handful of adjectives written with an actual that follow “na” rules anyways, so even this rule won’t work 100% of the time. Just 95% of the time. Which isn’t half bad.

Vocabulary

綺麗 = きれい = pretty; clean

Transcript

言語ガールズ #71

Some Of My Best Friends Are Books

Yellow: So to figure out how to conjugate and adjective I just look at the last syllable?

Blue: Well… usually.

Yellow: Usually?

Blue: Some adjectives that end in , like 綺麗 (きれい), actually follow rules instead of rules.

Yellow: So you would conjugate です and leave the adjective alone.

Yellow: How do I tell if an adjective follows the normal rules or not?

Blue: Most dictionaries mark whether an adjective uses rules or rules.

Blue: So be sure you’re familiar with your dictionary.

Yellow: Did you hear that Mr. Dictionary? My friend here thinks we need to get to know each other better.

Yellow: What’s that Mr. Dictionary? You think we should go out for ice cream? Good idea.

Gengo Girls #70: Good Old Days

Gengo Girls #70: Good Old Days

“ii” is one of those short common words that gets written out in hiragana more often than in kanji. You’ll be seeing いい a lot more often than 良い.

More trivia: “Yokatta”, the past tense of “good”, is also a common (but casual) stand alone sentence used to show relief and happiness. Did a friend manage to pass a difficult test? Yokatta. Did your cancer test just come back negative? Yokatta. Did a relative make it through a natural disaster unharmed? Yokatta.

Vocabulary

良い = いい = good; ok

Transcript

言語ガールズ #70

Good Old Days

Blue: One very important adjective is 良い (いい), which means “good” or “OK”.

Yellow: I bet that gets used a lot.

Blue: But when you conjugate いい you have to use the older pronunciation “よい”.

Yellow: More irregular conjugations. I’m not surprised.

Blue: So the past tense of いい is 良かった (よかった) and the negative is 良くない (よくない).

Yellow: And the past negative must be 良くなかった (よくなかった).

Yellow: Maybe I could just avoid conjugating いい.

Blue: You don’t think you’ll ever need a past tense “good”?

Yellow: The past is dead. Live for the present!

Gengo Girls #69: Why Would You Say That!?

Gengo Girls #69: Why Would You Say That!?

You don’t really hear negative adjectives all that often. People tend to say “That’s old”, not “That is not new”. The big exception is when you need to contradict or correct someone. If you get asked “Is that a new shirt?” it makes perfect sense to respond “No, it’s not new” (いいえ。あたらしくないです).

Vocabulary

難しい = むずかしい = difficult

Transcript

言語ガールズ #69

Why Would You Say That!?

Blue: Last time we talked about past tense adjectives.

Blue: So this time we’re going to talk about negative and past negative adjectives.

Blue: To make a negative adjective you replace the with くない.

Yellow: 新しくない

Blue: To make a past negative adjective you replace the with くなかった.

Blue: It’s a mix between the past rule and the negative rule.

Yellow: 新しくなかった

Blue: Now we can say things like: 日本語は難しくないです

Yellow: I understand what you just said…

Yellow: But at the same time I don’t.

 

Gengo Girls #68: Some Things Never Change

Gengo Girls #68: Some Things Never Change

I guess you could have a language with zero conjugations, but you would have to have a ton of context in every sentence. You couldn’t just say “I went to the store”, you’d have to say “ I [go] to the store in the past”. Which would be just as much work as conjugating your verbs. So hooray for conjugation!

Transcript

言語ガールズ #68

Some Things Never Change

Blue: When conjugating “ABです” patterns with adjectives you change the adjective but leave the です alone.

Blue: For example: To make a past tense sentence you change the adjective’s to かった.

Yellow: So 新しい would become 新しかった?

Blue: That’s right.

Yellow: And we don’t use でした even though we’re in the past tense?

Blue: Right. We stick with です.

Blue: “The smartphone was new” would be スマホは新しかったです

Yellow: Not conjugating です is nice, but having to conjugate the adjective is lame.

Blue: But if you didn’t conjugate anything how would people know what tense you’re using?

Gengo Girls #67: Starting Off Too Easy

Gengo Girls #67: Starting Off Too Easy

Of course you can also use “na adjectives” in casual “A ha B desu” patterns. But since we’re focusing on formal Japanese right now I’ll leave it up to you to find your own examples in your favorite Japanese media.

Transcript

言語ガールズ #67

Starting Off Too Easy

Blue: Adjectives that don’t end in are sometimes called “na adjectives”.

Yellow: Because they need an extra when placed before a noun.

Blue: Besides the rule these adjectives don’t have any conjugations.

Blue: You can just plug them right into any form of “ABです”.

Yellow: Past?

Blue: スマホは便利でした

Yellow: Negative?

Blue: スマホは便利ではありません

Yellow: Negative past?

Blue: スマホは便利ではありませんでした

Yellow: So our first lesson on adjective conjugation was all about adjectives that don’t need to be conjugated?

Blue: When you put it that way…

Gengo Girls #66: Techno-Obsessive

Gengo Girls #66: Techno-Obsessive

Some common adjectives actually come in both “i” and “non-i” flavors. For example, “small” can be written as both “chiisai” and “chiisa na”. In my limited experience the “i” versions are used more often than the “na” flavors, but it’s not like I’ve ever actually counted.

Vocabulary

新しい = あたらしい = new

便利 = べんり = convenient, useful

Transcript

言語ガールズ #66

Techno-Obsessive

Blue: Adjectives have different rules depending on whether they end in or not.

Blue: And it has to be an . Other “i” sounds like or don’t count!

Blue: adjectives can be used in “ABです”patterns or placed before a noun.

Yellow: スマホは新しいです。新しいスマホです。

Blue: Non-adjectives can be used in an “ABです”pattern but need an extra when placed before a noun.

Yellow: スマホは便利です。便利なスマホです。

Yellow: That’s a lot of grammar just for talking about smart phones.

Blue: You can use adjectives to talk about other things too…

Yellow: But why would you want to?

Let’s Program A JavaScript Game 15: The Computer Is Out To Get You

Game AI!!!

In computer science we use the term “AI” or “artificial intelligence” to refer to sophisticated problem solving programs that use fairly advanced algorithms to process and learn from data.

But in the gaming world we tend to use the term “AI” to mean “however the computer makes decisions whether it’s intelligent or not”. An enemy that does nothing but walk around in circles and shoot bullets obviously isn’t processing or learning from data but most people would call it an “enemy AI” anyways.

So a lot of “Game AI” isn’t actually “Computer Science AI”.

But that’s a good thing! “Computer Science AI” is designed to solve math problems. “Game AI” is designed to make games more fun. Since they have different objectives it’s no surprise that they usually have completely different code.

Sure, sometimes making a game more fun does involve inventing a “Computer Science AI” that can do things like analyze and coordinate hundreds of units moving through a changing battlefield.

But you’d be surprised how often you can make a game feel fun and smart with nothing more than a stupid random number generator and half a dozen “if” statements.

Which is a a roundabout way of me admitting that our game AI is going to be pretty stupid and random. So if you were expecting something clever, I’m sorry. You’ll just have to go back and reread the swarm intelligence series.

Requirements

So what are the goals for our game AI? Here’s what I came up with:

  1. New platforms should sometimes be higher or lower than the platform before them
  2. Platforms should never spawn lower than the bottom of the screen or higher than the top
  3. Platforms should get smaller and further apart as the game goes on
  4. Platforms need to always be reachable by a single jump. No game-breaking impossible layouts allowed.
  5. Viruses should appear at random locations instead of following a pattern

Leap Of Faith

Let’s tackle the platform problem first. As a reminder our current platform generating code is in the updateGame function and looks like this.

//Remove platforms that have scrolled off screen and create new platforms to take their place
if(platforms[0].x + platforms[0].width < 0){
   //Drop first platform by shift entire list one space left
   for( i = 0; i < platforms.length-1; i++){
      platforms[i] = platforms[i+1];
   }

   //Add new platfrom to end of list by placing it a certain distance after second to last platform
   var newPlatform = new Object();
   newPlatform.x = platforms[platforms.length-2].x + maxPlatformLength + maxPlatformGap;
   newPlatform.y = 350;
   newPlatform.width = maxPlatformLength;
   newPlatform.height = 20;
   platforms[platforms.length-1] = newPlatform;
}

First up is adding some randomness to the height of the platforms, which is actually a trickier problem than you might think. Sure, we could just use a random integer to set the “y” value of every new platform but then we run a huge risk of creating platforms the player can’t actually jump to or creating platforms that are too easy to jump to.

The issue is that when a platform is higher than the player they have less time to reach it than usual before falling to their doom, while if the platform is beneath the player they have more time than usual to make the jump.

More specifically, if you remember back to part 9 we calculated that it took thirty frames for the player to go from on the ground, to jumping to being back on the ground.

But if a platform is at the top of the player’s jump he will only have half that much time, fifteen frames, to reach it before he has started moving downwards and is now stuck below the new platform.

On the other hand if the platform is below the player’s starting position he will have the full thirty frames plus another dozen or so frames of falling before he’s gone too far.

So we can’t just use the same set horizontal distance between platforms of different heights. Platforms above the player need to be closer together. Platforms below the player need to be further apart.

To pull this off do we’re going to write a math function that can calculate how many frames it takes for the player to jump from one height to another. For this to work we need to know:

  • height difference
  • jump velocity
  • y acceleration per frame

Now if you’ll remember back to physics the equation for movement looks a lot like this:

end height = start height + velocity * time + ½ acceleration * time^2

0 = start height – end height + velocity*time + ½ acceleration * time^2

0 = change in height + velocity*time + ½ acceleration * time^2

And from there we can use the quadratic equation to solve for time. Just throw this function anywhere in your script:

// Calculate how many frames a jumping player will be in the air
// Based on the vertical distance they have to cover, their jumping vertical velocity
// and their vertical acceleration
// This is basically the physics distance formula plugged into the quadratic equation
function getFramesUntilLanding(dist, vel, acc){
   var a = (-1 * vel + Math.sqrt(vel*vel - 2 * acc * dist))/(acc);
   var b = (-1 * vel - Math.sqrt(vel*vel - 2 * acc * dist))/(acc);
   return Math.max(a, b);
}

Remember that the quadratic equation usually has two answers, which makes sense for a jump. A player will be five pixels off the ground both right after he jumps and right before he lands. We are only interested in how long it takes to land at a certain height so we take the max of the two values.

Another thing to watch out for here is that certain inputs to this function will return zero answers. Specifically, if the player is only moving fast enough to jump 150 pixels upwards and you ask how long it will take him to jump 300 pixels the answer is going to be “NaN”, the special JavaScript value for “not a number”. That’s what you get when you try to do impossible math.

To avoid this we need to know how high our player can jump so we can avoid asking for anything bigger than that. Looking at the code in updateGame we can see that starting jump velocity is 15 pixels per frame and that acceleration is 1 pixel per frame. That means that the player will keep moving upwards for 15 frames. Plugging that into our handy movement equation shows:

max jump height = 15 pixels/frame * 15 frames – ½ pixels/frame^2 * (15 frames)^2

max jump height = 112 pixels.

To give ourselves a little wiggle room we’ll round down and take 100 pixels as the max jump height. This means that a new platform should never be more than 100 pixels higher than where the player started.

As for platforms below the player, there’s really no limit as long as they’re still on the screen. Since gravity works downwards there’s no reason the player couldn’t safely jump or fall to a platform hundreds of pixels beneath them.

Prepare For Code Dump

With all that math and planning out of the way I was able to update our platform code. Just replace the platform generating code from the last section with this shiny new version:

//Remove platforms that have scrolled off screen and create new platforms to take their place
if(platforms[0].x + platforms[0].width < 0){
   //Drop first platform by shift entire list one space left
   for( i = 0; i < platforms.length-1; i++){
      platforms[i] = platforms[i+1];
   }

   // Add new platfrom to end of list
   // Platform is randomly placed somewhere within the jump range of the player
   // As the game goes on platforms get smaller and farther apart
   // Calculated max height of jump is about 100
   // Platform can't be higher than the max jump or 100 pixels from top of screen
   var minPossibleHeight = Math.max(platforms[platforms.length-2].y - 100, 100);

   //Platform can't be lower than the bottom of the screen
   var maxPossibleHeight = 380;

   //Random height between the max and min
   var newPlatformHeight = Math.random()*(maxPossibleHeight - minPossibleHeight) + minPossibleHeight;
 
   //Calculate how far the platform can be by multiplying speed of 10 by the time the player will be in the air
   var maxPossibleDistance = 10 * getFramesUntilLanding(newPlatformHeight - platforms[platforms.length-2].y, 15, -1);
   
   var newPlatform = new Object();
   //As the player earns points the platforms should get closer to being maxPossibleDistance apart
   newPlatform.x = platforms[platforms.length-2].x +
                   platforms[platforms.length-2].width +
                   maxPossibleDistance*(0.5 + 0.5 * currentPoints/TOTAL_POINTS_TO_WIN);
   newPlatform.y = newPlatformHeight;
   //As the player earns points the platforms should get smaller
   newPlatform.width = maxPlatformLength *(1 - 0.5 * currentPoints/TOTAL_POINTS_TO_WIN);
   newPlatform.height = 20;
   platforms[platforms.length-1] = newPlatform;
}

I think the code comments explain everything pretty well, so I’m just going to hit the highlights here.

Just like before we start by shifting the entire list left to make way for the new platform.

We then calculate where the next platform should go by choosing a random number between the min and max possible heights. Remember that in screen coordinates the top of the screen is y=0 and it gets bigger as you go down, which is why we find the min by taking the players location and subtracting his 100 pixel jump height and why the max is slightly smaller than the height of the screen.

Once we know how high the next platform is going to be we figure out how far away it can be by using our handy jump frame function to find out how many frames it will take to jump that high and then multiplying by ten, which is the players speed of 5 pixels per frame PLUS and extra 5 pixels per frame from the fact that the entire screen is moving backwards. This tells us exactly how far forward the player can move during his jump to the new platform.

Now that we have a height and know exactly how far the player can jump we’re ready to build a new platform. Height just gets slotted in but width and distance now get adjusted based on how close the player is to winning the game. For distance we start with gaps that are 50% the maximum jump distance and slowly increase them by another 50% as the player earns points. Platform size is the opposite, starting at 100% of max size and decreasing by up to 50% as the player moves.

Now I will admit that a lot of this is bad code. Even with the comments there are a lot of hard to understand hard-coded numbers floating around. But at this point we’re still prototyping and a certain amount of messy experimentation is OK. We’ll clean this up a little later.

Simple But Vicious Predators

After all the math involved in fixing up platform generation you’ll be happy to hear we can make the virus spawn pattern work pretty decently by changing just one line in the virus generation code:

newVirus.y = 300;

to this:

newVirus.y = player.y -50 + 100*Math.random();

This guarantees that new viruses will spawn in the general vicinity of the player with just a little bit of jitter to hide what we’re doing. And since the player should be randomly jumping all over the place this should make the viruses also appear all over the place.

Congrats! The Core Gameplay Is Done Now

We have a player that can move and jump.

We have platforms that spawn randomly and become smaller and further apart as the game progresses.

We have viruses that semi-intelligently place themselves in the heroes path.

We have a score system that lets the player win.

So we’re basically done with the actual “game” portion of this project.

So what’s left? A surprisingly large amount of stuff!

First, this prototype code badly needs to be cleaned up. And then we’ll take a few more sessions to add some special effects, music and basic animations.

Then, and only then, will we truly be done.

Gengo Girls #65: Ego-Grammatical

Gengo Girls #65: Ego-Grammatical

The main purpose of conjugation is to add information to a sentence. For example, a past tense verb conjugation tells you that the whole sentence is about the past. A negative verb conjugation tells you that the sentence means the opposite of what it would without the conjugation.

But when you think about it, it doesn’t really matter how information gets into a sentence as long as it’s there in the end. And while a lot of languages do this with verb conjugation there are plenty of languages with non-verb strategies for telling the listener that sentence is in the past or negative or plural or whatever.

Transcript

言語ガールズ #65

Ego-Grammatical

Blue: I think we’ve spent enough time on conjugating verbs for now.

Yellow: I agree.

Blue: Let’s talk about conjugating adjectives instead.

Yellow: Wait, what?

Yellow: I thought you could only conjugate verbs…

Blue: That’s true in English.

Blue: But in 日本語 adjectives have past and negative forms too.

Blue: There’s no reason that ALL languages have to stick to conjugating JUST verbs.

Yellow: I can think of a reason: That’s how I’m used to doing things!

Gengo Girls #64: Good Advice

Gengo Girls #64: Good Advice

We’ve covered a lot of grammar by this point and you should be starting to get a good idea of whether Japanese is something you want to spend a lot of time seriously studying or if you’d rather just keep learning bits and pieces of it at a slow but relaxing pace.

If you are serious now might be the time to buy a real textbook to expand on and reinforce the lessons you’ve learned with Gengo Girls. I would personally suggest Japanese Step By Step by Gene Nishi. It’s a very logical textbook that manages to break down most of the Japanese language into a series of easy to follow flow charts.

And for those of you who don’t want to spend a lot of time with an actual textbook: There’s nothing wrong with studying Japanese as a casual hobby and I hope you’ll keep turning to Gengo Girls as a weekly source of Japanese language trivia.

Vocabulary

テレビ = television

Transcript

言語ガールズ #64

Good Advice

Blue: Why don’t we practice our casual past tense by writing down what we did yesterday after school?

Yellow: Good idea!

Blue: Here’s mine.

Blue’s note: 宿題をした。勉強した。本を読んだ。

Yellow: Turns out I didn’t really do much yesterday.

Yellow’s note: テレビを見た。

Blue: Your grades would probably be a lot higher if you applied yourself just a little more.

Yellow: You sound just like my mom!

Gengo Girls #63: Overcompensation

Gengo Girls #63: Overcompensation

As usual the irregular verbs are also super common verbs, which is a good thing because it means you’ll get lots of exposure. After hearing “shita”, “kita” and “itta” a hundred times each you won’t even have to think about conjugating them; the right word for the situation will just pop into your head.

Transcript

言語ガールズ #63

Overcompensation

Yellow: I’m ready for the irregular casual past tense verbs.

Blue: する becomes した

Blue: 来る (くる) becomes 来た (きた)

Blue: 行く (いく) becomes 行った (いった)

Yellow: That’s it?

Blue: That’s it.

Yellow: Then what are we supposed to do with the rest of today’s panels?

Blue: I’m sure you’ll think of something.

Yellow: So three men walk into a bar. One of them has a cat, one of them has a duck and one of them has a baked potato. The bartender turns to the first man and says…

Blue: We don’t have quite THAT much space.