Triple Triad

**Triple Triad** is a mini-game included with Pokémon Essentials. It is a Pokémon-themed version of the Triple Triad mini-game in *Final Fantasy VIII*.

## How to play

Triple Triad is a card game played on a 3x3 board. At the start of a game, each player chooses 5 cards they own to be their hand for that game, and then take turns playing their cards in unoccupied spaces of the board.

Each card has 4 numbers on it, one per side, which range from 1 to 10 (known as A). If a card is played which touches an opponent's card on a side, the touching numbers are compared. If the number on the newly-placed card is higher than the opponent's card's number, that opponent's card is captured and swaps ownership. Nothing happens if the newly-placed card's number is equal or less than the opponent's card's number.

The goal is to control the most cards on the board at the end of the game, when no further cards can be played.

The winner receives one random card used by the loser. No cards change hands if the game is a draw.

### Rule variations

There are a number of rules and modifications which can be applied to a Triple Triad game. These are all optional, and any combination of these rules can be applied.

This bonus only applies to a newly-played card attempting to capture other cards; the bonus is removed afterwards. It will not apply if the card attempts to capture other cards because of the "Same Number Wins" rule (because it wasn't a newly-played card).

In addition, the prize for winning/cost for losing a game can be changed to be one of the following instead:

## Card details

A Triple Triad card features a species of Pokémon. All cards of a species are identical. The code for a card is in `class TriadCard`.

The card's type will be the first type of that species, as defined in the PBS file "pokemon.txt". The only exception is if the first type is Normal and the second type isn't (e.g. Flying), in which case it will be the second type instead.

The four numbers on each card derive from the base stats of that card's species, as defined in the PBS file "pokemon.txt":

* The west number uses the base Attack and Speed.
* The east number uses the base Defense and HP.
* The north number uses the base Special Attack and Speed.
* The south number uses the base Special Defense and HP.

The exact calculations that turn base stats into card numbers, and card numbers into a price, will not be described here. They are in `class TriadCard`. A card's price can be between $10 and $24,000.

## Playing Triple Triad

The first step is to check whether the player has enough Triple Triad cards to play. You can check this with:

```
pbCanTriadDuel?

```

This returns TRUE or FALSE accordingly.

To play Triple Triad, use the following script:

```
pbTriadDuel("Zaphod", 0, 5)

```

The three arguments are the opponent's name, minimum level and maximum level. The levels can be between 0 and 9 inclusive, and the maximum level must be higher than the minimum level.

Opponents are generated with a random set of cards. 200 possible cards are randomly generated and listed in order of the sum of their four values. The minimum and maximum levels determine how far down this list to choose 5 cards from (higher levels means stronger cards).

This will begin a basic game of Triple Triad.

### Additional arguments

You may wish to customise certain games. You can do so by including additional arguments in the above script. A full list of possibilities is as follows:

```
pbTriadDuel(name, minLevel, maxLevel, rules, oppDeck, prize)

```

* "`rules`" is an array of rule phrases, each of which applies one of the rule variations mentioned above.
* "`oppDeck`" is an array of 5 Pokémon species, which set the 5 cards you want that opponent to use (rather than choosing them randomly). Each one is a colon followed by the species ID.
* "`prize`" is a Pokémon species (with a colon in front of it). If the player wins the game, rather than applying the game's prize rule, they will instead gain 1 card of this species. Losing and drawing the game are not affected.

If you don't want to use one or more of these options, put "`nil`" in its place (without quote marks).

Some examples are as follows:

```
pbTriadDuel("Alice", 0, 5, ["countunplayed", "samewins", "elements", "direct"])
pbTriadDuel("Tim", 0, 5, nil, [:BULBASAUR,:CHARMANDER,:SQUIRTLE,:PIKACHU,:CLEFAIRY])
pbTriadDuel("Sophie", 0, 5, nil, nil, :ARCEUS)

```

### Result of the game

The `def pbTriadDuel` will return a value depending on the outcome of the battle:

* 1 = player won
* 2 = player lost
* 3 = draw

You can use this information in a Conditional Branch in an event, like so:

```
@>Conditional Branch: Script: pbTriadDuel("Zaphod", 0, 5) == 1
  @>Text: You won!
  @>
 : Else
  @>Text: You lost or drew the game...
  @>
 : Branch End
@>

```

## Gaining cards

To give the player a Triad card, use the following script:

```
pbGiveTriadCard(:PIKACHU)
pbGiveTriadCard(:SNORLAX, 3)

```

The number is how many of that card to give (1 by default). This will return TRUE if the card(s) were added, and FALSE if not. It does not display any messages.

### Card Shop

There are two scripts you can use to buy or sell Triad cards. They are as follows:

```
pbBuyTriads
pbSellTriads

```

"`pbBuyTriads`" will let you buy cards of any species that are listed as owned in the Pokédex.

"`pbSellTriads`" will let you sell any cards you possess. You can sell cards even if you would end up without enough cards to play a game. Cards are sold for a quarter of their buying price.

## Viewing cards

To show the player a list of the Triple Triad cards they have, use the following script:

```
pbTriadList

```