Monday, September 5, 2011

Virtua Subbuteo Computer AI

In the next few paragraphs, I am gonna attempt to explain what the computer is thinking when he plays against ... YOU! It is subject to evolve as new versions come out but I will make every effort to keep track of the changes.

Blocking Strategy


That's the easy part. First, the computer sorts the red players (your players) with respect to increasing distance to the ball. For each red player to block, the computer considers a blocking location between the red player and the ball. It then must figure out which of its own players (the blue players) should actually make the block. The blue players are sorted with respect to increasing distance to the blocking location. The first blue player that has a clear path to the destination location is selected and flicked by the computer. In other words, the computer tries to block the red player that's closest to the ball. If it can't, the computer goes to the next one, etc.

The level of play you chose at the beginning determines how accurate the block is gonna be. The level of play affects the speed at which the blue player is gonna be flicked, not its direction. At the highest level, the block will land right in between the red player and the ball because the computed correct speed (flick power) is not modified.

Attacking Strategy


Ball is not in the shooting zone


The computer will attempt to advance the ball towards a location right past the shooting the line and dead center width-wise (if not possible, somewhere closer to the current ball location). The computer cycles through all its players (blue players) until there's one that has a clear path to the ball and can hit the ball to the desired location. If the ball can not be hit to the desired location, the computer considers having the blue player hitting the ball to the left and to the right until the ball can be moved the desired distance, if not to the desired location. If the computer cannot find a player to flick, it will say that it is giving up and you will gain possession of the ball.

As you can read, the computer kinda tries to advance along the center of the pitch. In the future, I might try to have him advance more along the sidelines.

At present, the difficulty level has not been integrated into the computer ball advancing algorithm. Maybe in future versions.

Ball is in the shooting zone


When the ball is in the shooting zone, the computer figures out where the ball should end up for a goal to be scored (between goalie and either post). It then cycles through its players (the blue players) until it finds one that has a clear path to the ball, preference being given to the player that is best aligned with the ball and target location. Needless to say that, if the ball is in the shooting zone, there is a blue player with a clear path to the ball and there is a clear path between the ball and the goal, it's very likely a goal will be scored.

At present, the difficulty level has not been integrated into the computer shooting algorithm. Maybe in future versions.

Tuesday, August 30, 2011

Virtua Subbuteo rules of play

Main game controls:
* esc to end the game
* f1 to show the game information
* f4 to switch between the screen modes (full or windowed)
* f5 and f6 to save and load the game

At the beginning of the game, you are asked for a number. It is the total number of flicks that will be made in the game (by you or the computer). It was either that or a clock, and I chose that. Each time a flick is made, the global flick counter decreases by 1. When the counter reaches 0, the game is over.

How to play?


You have the red team, the computer has the blue team. Pay close attention to the possession and turn buttons. It tells you who has possession and most importantly, whose turn it is to play. Always wait until the play has stopped before doing anything!

Regular play


If you have possession of the ball (attacking) and it is your turn to play, you select a figurine to be flicked with a mouse left-click. Once a figurine is selected, it can be aligned with the 'left' and 'right' arrow keys. Note that once a figurine is selected, it will have to be flicked since the selection cannot be changed. The 'space' bar is used to flick the figurine. The longer the bar is pressed, the further the figurine will be flicked. An attacking figurine cannot be flicked more than 3 times in succession unless the ball hits another attacking figurine (resets the flick counter).

After a successful flick from the attacking player, the defending player is allowed a block. Selection is made with a mouse left-click as for the attacking flick. If the flicked figurine hits another figurine or the ball, a 'back' is awarded. The figurines then always go back to where they were before the offending flick.

The attacking team loses possession if:
* the flicked figurine misses the ball, or
* the ball hits a defending figurine, or
* the flicked figurine hits a figurine before hitting the ball (free-kick awarded).

Of course, the attacking team loses possession also if, for example, the ball goes out of play and it was touched last by an attacking figurine. This is part of non-regular play and is explained below.

Non-regular play


Throw-in


You have a throw-in when the ball goes by either touch line. The throwin goes against the team that last touched the ball. The table soccer forcing rules are not applied.

When a throw-in is awarded, the figurine to take the throw-in is selected with a mouse right-click. The attacking and defending teams are allowed 1 positional flick each. The mouse left-click is used to select the figurine to be flicked for positioning. Once all positioning flicks have been performed, the figurine previously selected to take the throw-in is positioned with a mouse right-click and is now ready to kick the ball (regular play then resumes).

Corner


You have a corner when the ball goes by the goal line and it was last touched by the team occupying the half of the pitch where the goal line is. The corner goes to the opposing team. The table soccer forcing rules are not applied.

When a corner is awarded, the figurine to take the corner is selected with a mouse right-click. The attacking and defending players are allowed 3 positional flicks each. The mouse left-click is used to select the figurine to be flicked for positioning. Once all positioning flicks have been performed, the figurine previously selected to take the corner is positioned with a mouse right-click and is now ready to kick the ball (regular play resumes).

Spare goal-keeper


The goal-keeper when in goal cannot be moved. If you are in possession of the ball, you may call in the spare goal-keeper (to kick the ball) by pressing the 'S' key. The spare goal-keeper is positioned (in or behind the keeper's box) with a mouse right-click and is now ready to kick the ball (regular play resumes). The spare goal-keeper is automatically removed from the field of play after his flick whether or not possession is maintained.

Goal-kick


You have a goal-kick when the ball goes by the goal line and it was last touched by the team occupying the half of the pitch where the other goal line is. The goal-kick goes to the opposing team. The table soccer forcing rules are not applied.

When a goal-kick is awarded, all figurines are repositioned automatically. The (spare) goal-keeper is positioned (in or behind the keeper's box) with a mouse right-click and is now ready to kick the ball (regular play resumes). The spare goal-keeper is automatically removed from the field of play after his flick whether or not possession is maintained.

Free-kick


A free-kick is awarded when an attacking figurine hits another figurine before the ball. The free-kick is awarded to the opposing team.

When a free-kick is awarded, the figurine to take the free-kick is selected with a mouse right-click. The attacking and defending players are allowed 1 positional flick each. The mouse left-click is used to select the figurine to be flicked for positioning. Once all positioning flicks have been performed, the figurine previously selected to take the free-kick is positioned with a mouse right-click and is now ready to kick the ball (regular play resumes).

Kick-off


A kick-off is awarded to the defending player when a goal is scored.
When a kick-off is awarded, all figurines are repositioned automatically. The center-forward is positioned with a mouse right-click and is now ready to kick the ball (regular play resumes).

Offside


An attacking figure is in an offside position if:
* it is in the opponent's shooting zone, and
* it is closer to the opponent's goal line than the ball is, and
* it is closer to the opponent's goal line than the last 2 defenders (including the goalkeeper) are.

If the ball moves forward, is in the shooting zone and is past the 2nd last defender (including the goalkeeper), an offside position is called and a free-kick is awarded for the defending player.

Onside (tick) flick


If you are in possession of the ball, you can request an onside flick to reposition a figurine in an offside position by pressing the 'T' key. The mouse left-click is used to select any offside figurine to be flicked for repositioning. The defending team is allowed 1 positional flick before regular play resumes. You are allowed up to 3 tick flicks per possession. If you have already used your 3 tick flicks, nothing will happen when pressing the 'T' key.

Goal scoring


A goal can be awarded only if the ball was in the defending player's shooting zone prior to the shot. If it was not, a goal-kick is awarded to the defending player.

Goal area


If a figurine (beside the goal keeper) is inside either goal area, it is automatically moved out of the goal area. If the ball is inside either goal area, it is repositioned near the penalty spot and possession goes the team whose goal area it is.

Monday, August 29, 2011

Virtua Subbuteo

Virtua Subbuteo is an attempt at recreating Subbuteo, the table football game, on Windows PC.

The table football rules used in Virtua Subbuteo are inspired from the ones provided by FISTF (Federation of International Sports Table Football). You certainly don't need to know the FISTF rules to play Virtua Subbuteo, you just need to check out the Virtua Subbuteo rules of play or press F1 when playing the game.

Virtua Subbuteo has been developed using GameMaker for Windows, a program published by YoYo Games.