Wednesday, 17 October 2012

Flocking Algorithms

Flocking


A Flocking Behavior is a simple set of rules that can emerge into a set complex global behaviors. There are many uses in game and simulator development for flocking. Whether you want you units to move around the map or you want to simulate a flock of seagulls or fish you can even emulate crowds, flocking provides a base for you to work of off.

There are three basic rules to flocking, separation, cohesion and alignment. I have represented these rules below in the image.



Lets talk about how you can actually implement a basic flocking behavior.

Separation:

The function code below is how you calculate the separation vector for each boid.  This code loops through every boid and checks if the position between the object being updated and the object that the loop is processing is within the minimum allowed distance by your code.

In my implementation, not shown in the code below, I actually only pass each boid the boids that are close to  it already.

Pseudo code:


FUNCTION separate(boid bj)       
         Vector c = 0;  
         FOR EACH BOID b  
             IF b != bj THEN  
                 IF |b.position - bj.position| < 100 THEN  
                     c = c - (b.position - bj.position)  
                 END IF  
             END IF  
         END  
         RETURN c  
 END FUNCTION 


Cohesion:

Cohesion is what makes the boids stick together in the local groups. Without it flocking really cannot exist. It works by calculating the center of the mass of the local flock (average position).

In my implementation, not shown in the code below, I actually only pass each boid the boids that are close to  it already.

Pseudo code:



 FUNCTION cohere(boid bj)  
  Vector pcj  
  FOR EACH BOID b  
   IF b != bj THEN  
    pcj = pcj + b.position  
   END IF  
  END  
  pcj = pcj / N-1  
  RETURN (pcj - bj.position) / 100  
 END FUNCTION  




Alignment:

Alignment works by averaging the velocities of all the boids in the local area to get the boids moving in the same general direction.

In my implementation, not shown in the code below, I actually only pass each boid the boids that are close to  it already.

Pseudo code:



 FUNCTION align(boid bj)  
  Vector pvj  
  FOR EACH BOID b  
   IF b != bj THEN  
    pvj = pvj + b.velocity  
   END IF  
  END  
  pvj = pvj / N-1  
  RETURN (pvj - bj.velocity) / 8  
 END FUNCTION  




Moving the Boids:

This is the function that gives your there acceleration and velocity then adjusts there position. It simply calls the above functions and then sums their result.

In my implementation I do more processing on the vectors values, I normalize each vector and then multiply by a weight factor that I can tweak for each vector. After this I also normalize the end result to get a smoother motion.

Pseudo code:



 FUNCTION flock()  
  Vector separateVector, cohereVector, alignVector  
  Boid b  
  FOR EACH BOID b  
   separateVector = separate(b)  
   cohereVector = cohere(b)  
   alignVector = align(b)  
   b.velocity = b.velocity + separateVector + cohereVector + alignVector  
   b.position = b.position + b.velocity  
  END  
 END FUNCTION  



Conclusion:

In the above code and descriptions I have outlined the basic structure that I have used to create a simple flocking behavior, this code is just as valid whether you are dealing with a 2D or 3D space. There are improvement to the code, some of which I have added and others which I have not.

You can rotate the object so it is always facing the direction it is traveling in. You can also add rules that handle collision with other objects, and steering behaviors to create an even smoother appearance to the object moving.


Liars Dice Modification

This week we where tasked with removing the Positive Feedback loop in a popular version of the game of Liar's Dice. Each of my team members had to come up with 1 changed, added or removed rule.

Pity mod:
If a player has only one die left, they can go down or up on their call, rather than just up. The exception being that if there are two players left this rule no longer takes effect. 

Examples: A player calls 4 sixes, the player with 1 die left can in addition to the normal rules can say 3 sixes or 4 fives.

Result:
  • This allowed weaker players to stay in the game longer.
  • This somewhat reduces positive feedback loop.



Holdem mod:
All lost dice get placed in the center of the table and are rolled.  These dice count towards the global total of dice.

Result:
  • It turns out doesn't affect game play that much.
  • The players who are better at counting dice do better.
  • This actually reinforces positive feedback loop, rather than negating it.



Loser wins mod:
  • Winner is person who first loses all their dice.
  • Calling a bluff correctly loses you a die.
  • Calling a bluff incorrectly makes the person the bluff was called on loses a die.
  • Calling a spot on correctly makes you lose a die.
  • Calling a spot on incorrectly makes you gain a die.
Result:
  • This rule makes it get considerably harder as you lose dice.
  • The positive feedback loop replaced with a negative feedback loop.



Handicap mod
Everyone who didn't lose a dice each round has to reveal one of their dice in the next round
unless you have 1 die left.

Result:
  • The more you win the more other players know about your hand.
  • This hinders the positive feedback loop but does not remove it completely.


Lucky guesser mod:
If you call a spot on, you reacquire one lost die, but you can still only have as many as you started with

Result:
  • This rule actually enforces positive feedback loop.


Blind mod:
Every player gets to see everyone's dices but their own.

Result:
  • The less dice you have the harder it is for everyone to play.
  • This reverses positive feedback loop.




A couple of pictures taking during the play testing yesterday.

Always good to have a person play who is not in your group, Thanks Justin.


"Required" dice rolling picture.

Sunday, 14 October 2012

Battleship: Revision

Yesterday our in class we were tasked with modifying the classic game Battleship. For me this was a great experience because Battleship was one of my favorite games growing up, and I had lots of ideas back then on how to modify it, it was nice to get a chance to do that. Of course having only 20 minutes meant that my group had to move non-stop to finish the concept. Thankfully, we finished with only seconds to spare.

Lets talk about the rule modifications we made, we added 5 addition rules.


Storms- A storm is very dangerous. A storm occupies a single tile and damages that part of the ship during the turn. A storm is moved every full round (after all players have went). To determine where it went, players roll 2 D10’s and whatever the result is, the storm goes to that tile on both sides.

Cruise Missile- Every player gets three cruise missiles and can use them during the start of their turn instead of a regular attack. When using a cruise missile, a player announces a ship they wish to attack; they do not need to have previously hit the ship. A player rolls a D10 and if the result is 6 or greater, they successfully hit an undamaged part of that ship. If it is 5 or lower, they miss and it is the next players turn.

Movement- Every turn, a player can choose to move. When moving, a player can move 1 ship either three squares up or three squares down. Or, a player can choose to take up all three movements and rotate their ship along either end.

Repair crews- Every turn you can choose to repair a section of a ship. You simply state you are using a repair, and repair a single tile of a ship. You have a total of 5 repairs you can use.

Carpet Bomb- As long as your aircraft carrier is still up; you can choose to do a carpet bombing run. When doing a carpet bomb, you select a single vertical line (a line facing both players) and you hit every tile along that line.  You only hit the tiles on your opponent’s side. You can only do this once.  



Now some fast paced action pictures...






















Wednesday, 10 October 2012

Dig Dug



This week we took the classic Atari game Dig Dug and transformed it into a monster killing card game.

Concept from Original:
In the Atari version game the player is required to dig through the ground and kill all the monsters. This is fairly hard to do in a card format so we got creative.

In our game the player digs by flipping over a card from the stack, and players kill monsters with items, either pumps or rocks or other special items collected from digging. The winner of this game is the player who kills the most monsters when there is no cards left to dig.

Players:
2-6

Game Setup:
  • To start the game each player is dealt 7 cards from the top of the stack.
  • The player that goes first is the last player to eat some pineapple.
  • Play proceeds to those players left.
Rules:
  • On a players turn, he first draws (digs) a face up card from the stack, if it is a monster he must fight it, if it is anything else it can go into his hand.
  • If the player did not draw a monster, he may then play a monster if he chooses.
  • If the player draws a monster and defeats it, he draws (digs) a card face down from the stack. A player will draw 1 card for each monster card defeated.
  • In order to kill a monster cord(s) a player must play items that when totaled are greater than or equal to the number of monsters in the combat.
  • If the player cannot or does not want to kill the monster, he can run away discarding any monsters and items in play.
  • The max hand size at the end of your turn is 7 cards; you must discard down to this number in order to end your turn.

Cards:

There are a total of 105 cards in the deck.

  • Monster:
    • Pookas:
      • Pookas are the basic enemy in the game, they are fairly weak and players should not have much trouble dealing with them with starting cards. There are three types of cards with one, two and three Pookas.
    • Fygars:
      • Fygars are the harder enemy to kill, they will be quite challenging without the right amount of item cards. There are three types of cards with three, five and eight Fygars.
  • Pump:
    • Small:
      • The small pump can kill 1 monster on a card.
    • Medium:
      • The medium pump can kill 2 monsters on a card.
    • Large:
      • The large pump can kill 3 monsters on a card.
  • Boulders:
    • Small Boulder:
      • The small boulder can kill one monster on a card.
    • Medium Boulder:
      • The medium boulder can kill two one monsters on a card.
    • Large Boulder:
      • The large boulder can kill three one monsters on a card.
    • Humongous Boulder:
      • The small boulder can kill all the monsters in the active combat.
  • Special:
    • Carrot:
      • The carrot grants +1 monster to a combat.
    • Turnip:
      • The turnip grants +1 monster killed to any pump or boulder.
    • Mushroom:
      • The mushroom kills 2 addition monsters.
    • Eggplant:
      • The eggplant adds 2 addition monsters to the combat.
    • Green Pepper:
      • The green pepper can either kill 3 monsters or add three monsters to the combat.
    • Tomato:
      • The tomato allows the player to search through the discard pile and place one of the cards into his/her hand.
    • Watermelon:
      • The water melon lets you peek at and reorder the top 5 cards of the stack at any time, even before another player would draw.
    • Pineapple:
      • The pineapple card ends the current combat, it may be played by any player at any time on any combat, and no reward is drawn, and no points are earned.
    • Ghost:
      • The ghost card allows a player to add a monster card to an active combat of any player.

Card Sheet:
















Wednesday, 3 October 2012

Gem Hunter



This week for our collection game, my group made a casual collection game called Gem Hunter.
We stuck to the basic principle of KISS this week, after last week where are game was still good but had complex rules.

The game involves players moving around the board trying to recover more of gems than any other player, they do this by rolling a die and moving tiles, they can reveal the tile that they land on and resolve it.

In order to play this game, you need the 100 tiles, 1 d4 die, 1 d6 die turn order, 40 assorted gem tokens and 4 player tokens.


Set Up & Rules

  • All 100 tiles (or as many as players have decided on) must be shuffled and laid out on a 10 x 10 grid (or to the specifications of players).
  • All 4 players take turns to roll the dice. The player with the highest roll begins. If 2 players roll the same highest number, they roll again. 
  • The player with the highest roll then proceeds to choose a tile to enter the board on. Should this tile be a trap tile, the player is kicked off the board and must try again on his next turn. Play passes on to the left of the player.
  • As all players enter the board, the objective of the game is to collect the most gems while avoiding trap tiles. To do this, players roll the dice and move the appropriate number of spaces in any direction (including diagonal).
  • NOTE: No player is allowed to land on the same tile as another player, simply move to a tile beside him/her.
  • If a player lands on a trap tile in-game he/she loses a gem collected and must skip his/her next turn. If the player owns no gems, he/she must simply skip their next turn.
  • Should a player land on an empty space or a trap tile, they turn over the tile once the effect has occurred. Gem Tiles, however, remain flipped up.
  • Once all gem tiles are turned up, the player with the most gems wins the game and is crowned the "Gem Hunter"!
  • Should 2 or more players have the same amount of gems once all Gem Tiles are flipped, ...



Inspiration:

Our original concept was a much more complex gem collection game based in a lost tomb, we discussed many aspects but quickly the rules became complex and we decided instead to strip out the complexity and stick with a basic concept of moving around tiles and collecting gems, we add randomness in as well because the tiles are flipped down.


Pictures:

These are the different tiles that we have in the game.








Thursday, 27 September 2012

Pride, Prejudice & Pirates

For our first prototype deliverable, using the provided theme of Jane Austen and Pirates we decided on her book Pride and Prejudice.

Trying to turn a work her book into a game was not an easy task, because her books written in such a way that saying true to the fiction is easy, adding pirates makes the task even harder. We solved this issue by abstracting the general theme from Pride and Prejudice which is about finding a man to get married too. We did put it back into the story once we had nailed down the theme.

For the format we stuck with a simple race to the end model, where the person who reaches the end first gets married.

Story:

Pride and Prejudice is about a aging father who has 5 daughters and no sons of which to inherit his property, so a distance cousin will inherit everything, leaving his wife and daughters with nothing unless they can marry off to a man, the wealthier the better so the daughters can help support each other after their father dies. The rest of the story is several love stories mixed with the lengths that the girls go too and will not go too in order to get married.

We tie this in with the board game by having each player play as one of the 5 daughters in a race to get married first, in order to do so they will have to deal with their pride prejudice and a few pirates thrown into the mix.

We wrote a piece of flavor text to help linking together the book and the game:

Live a classic Jane Austen love story!  Ms. Bennet wants her daughters married off to rich, attractive men.  Take control of Jane, Elizabeth, Mary, Kitty, and Lydia Bennet from Jane Austen’s fantastic novel, Pride and Prejudice, and race your sisters to the altar!  But you’d better watch out, pirates are after your precious booty!  Avoid the pirates, wear your best dress, and put on your best smile, because the first player to get to the end gets married and wins!


Equipment:  1 six-sided die, 5 player tokens, PP&P cards

Rules:
  • Players sit around the board.  Player who last read a Jane Austen novel or watched a Jane Austen movie goes first
  • If no one has read a Jane Austen novel or seen a Jane Austen movie (shame!), oldest player goes first
  • Roll the die, and advance the amount of spaces shown on the die
  • Play passes to the left
  • If you land on a Jolly Roger tile, you must go back to the last Jolly Roger you passed, or if it is the first one, go back to start
  • If you land on a PP&P tile, take a PP&P card from the deck.  You must read the card out loud
  • NOTE: If by the events of a card you land on a PP&P tile, do not draw a card.  Similarly, if you land on a Jolly Roger by the effect of a card, you are not affected by the tile
  • NOTE: Some cards may be saved and used at a later point, the others must happen immediately
  • Multiple players may stand on the same tile, a lady does not bicker over such nonsense
  • First player to the end wins

Have fun!

Pictures: 
The Board
Our Pride Cards
Our Prejudice Cards






Tuesday, 25 September 2012

Territory acquisition: Corporation Exploitation

Lets talk about territory acquisition games. The core mechanic revolves around taking over some form of territory and then holding onto it until the end of the game when a variety of winning conditions determine the winner.

Our games theme is that you are a corporation moving into a resource rich but economically poor region of earth and your goal is to control as much territory as possible and control it. It is a tile based game which enhances the replay value because the pseudo board you play on each game will be different.

With our territory acquisition game we keep the essence of controlling territory but a add few helping mechanics in order to spice up the game.

We make certain territories worth more than others, creating a conflict over the higher value territories.
We also impress upon players that owning the territory alone will not be enough, taking care of your territories through various mechanics is important, much like in the real world. Due to the game relying on more than just owning territories we had to develop a point system to create a definite winner which reflects how many territories you have and how well you look after them.

Inspiration:

The inspiration for this game comes from a series of articles in the Global & Mail about corporations in Africa that deals with how they are coming in and buying up land and dealing with the locals in both good and bad ways.

Goal:

In this game you play a corporation moving into a new land, and your goal is to control as much territory as possible, but the catch is that owning territory isn't enough to win you the game alone. You need to take care of territories as well.

Rules:


Corporation Exploitation

Game Setup:
The tiles will shuffled be laid out in an 8x8 grid face down for randomness and then flipped over revealing the tiles.
The last player to purchase a consumer goods item worth over a $100 will go first.
Each player starts with $1000, and can purchase territory, the first territory they purchase must be on the edge of the board, and all future territories must be connected.

Game Pieces:
64 * 3 Tokens of one color for industrial buildings.
64 * 3 Tokens of another color civil buildings.
64 Tokens of another color for the happiness meter.
64 tokens each of 4 colors, one for each player.
2 D8 dice and 2 D10 dice.

Turn Steps:
  1. Collect Income
  2. Roll Disease Dice
  3. Purchase Improvements
  4. Trigger events
  5. Purchase territory 
  6. Economically Conquer Territory


Income:
Each tile generates a different amount of money each turn; happiness will increase or decrease this value by 33% times the happiness value of the tile eg.-3 happiness results in 100% less income and +3 happiness results in %100 more income. Income is rounded to the nearest $50 increment.

Disease Dice:
Every turn the player rolls the 2 d8 dice, first die rolled is the rows and the second die rolled is the columns on the tile board. This tile becomes affected by disease reducing the happiness by 2.

Purchase Improvements:
Players may purchase improvements from the improvement table for their listed cost and place them on their territory that they choose. They then apply any effects to the territory. You must purchase industry improvements in order from top to bottom of the tile, civil improvements can be purchased in any order.

Trigger Events:
Players may purchase events from the event table and then pick a territory to affect.

Purchase Territory:
Players may purchase territory that is currently un-owned as long as it is connected to their territories.

Economically Conquer Territory:
Players may attempt to economically conquer a territory from another player; you may only attempt one of these per turn. The territory must be connected to their territories.
In order to take over other players tiles the two players involved roll a d10, a negative happiness will affect the conquest players roll by reducing it by that amount and a positive one will affect the conquers roll by reducing it. In addition players can throw money at the territory, for each $100 dollars a player spends they increase their roll by 1. Highest roll gets the territory.
Game Length:

The game will last for 24 turns, at the end of the game the player with the most points which are used as a scoring system rather than a territory direct count because in this case it isn’t size that matter but how you take care of what you control.
Trading:
Players can trade territories in several ways, either in a direct swap or buy offering a cash value, or a combination of the two. You cannot trade for territories that do not touch your territories or would not touch your territories after the trade.
Strategic Alliances:

Players can form these in order to strengthen their position on the board; there is no in game benefit other than not having to worry about being attacked by that player. There is no formal policy for these set in place, which therefore means there is no penalty for breaking them or when such a break can occur.
Winning the Game:

After the 24 turns are over, players tally up all the points for their controlled territories and buildings on the territories. You also tally up your happiness values and then add them to the territories and buildings score. The player with the most points wins.

Happiness:
The happiness meter on a territory unaffected by anything starts at the higher of the two yellow markers. For each civil improvement on a territory it generates 1 happiness per turn.

Tiles:
Icon
Name
Cost
Points
Income
Grain
$200
3
$+100
Metal
$400
5
$+200
Rubber
$600
7
$+300
Oil
$800
10
$+400
Gems
$1000
15
$+500

Events:
Name
Cost
Happiness
Propaganda
$250
+/- 1
Industrial Sabotage
$450
-2
Entertainment Event
$500
+2
Tax Rebate
$750
+3
Hire Rebels
$650
-3
Disease
N/A
-3

Improvements:
Icon
Name
Cost
Points
Happiness
Income
School
$250
1
+1/turn
$-50
Sanitation System
$500
2
+1/turn
$-100
Hospital
$750
3
+1/turn
$-150
Ore/Gem Mine
$200
1
-1
$+100
Oil Well
$200
1
-1
$+100
Grain/Rubber Farm
$200
1
-1
$+100
Refinery
$400
2
-2
$+200
Smelter
$400
2
-2
$+200
Irrigation System
$400
2
-2
$+200
Jewelers Workshop
$400
2
-2
$+200
Factory
$600
3
-3
$+300



Lets look at tiles that comprise the game.

The Gem tile is the most valuable, and there are the fewest of them in the game.

 The Grain tile is the cheapest and is the most plentiful in the game.

The Metal tile is a medium-low priced tile and is not as plentiful as the Grain tile but there are still a fair number of them.

The Oil tile is a medium-high priced tile and is not as rare as the Gem tile. 

The Rubber tile is a medium priced tile and is not as plentiful as the Metal tile but there are still a fair number of them.