The Example - pcaston2/tupo GitHub Wiki

#The Example

The example is a state on the host which needs to be passed to the device and properly configured there for accurate play.

ID Card Type Priority Played State Alive
0 Barracus Commander 0 Turn 0 Yes
1 Lightning Cannon Fortress 0 Turn 0 No
2 Corrosive Spore Fortress 0 Turn 0 Yes
3 Chainslicer Assault 3 Turn 1 Yes
4 Tempest Keep Structure 1 Turn 3 Yes
5 Anvil Assault 4 Turn 5 No
6 Cyberpod Assault 7 Hand
7 Iron Maiden Assault 5 Hand
8 Lead Dozer Assault 2 Hand
9 Chainslicer Assault 6 Deck
10 Missile Silo Structure 8 Deck
11 Judgement Nova Assault 11 Deck
12 Iron Maiden Assault 10 Deck
13 Chainslicer Assault 9 Deck

Note: Some cards may have priorities marked for random prioritization. These prioritizations are chosen at random at this point, and then offset so as not to conflict with cards on the field with a strict order

Here we see various cards in play already and some of them are dead. There are cards in hand and cards in the deck. Let's assume the deck is shuffled thusly:

ID Card Type Priority Played State Alive
13 Chainslicer Assault 9 Deck
12 Iron Maiden Assault 10 Deck
9 Chainslicer Assault 6 Deck
11 Judgement Nova Assault 11 Deck
10 Missile Silo Structure 8 Deck

This can be accomplished with a modern Fisher-Yates Shuffle run in series. The host should offer the shuffle indexes in the field parameters. In this case if would be 9 through 13.

After the shuffle, a series of exchanges must take place to simulate drawing. Here we process the range starting 3 spots back from the deck, in this case 6, and go until 13. The range is passed by the host, in the event that a different range (or no range) be required.

Because there are duplicates the host will have provided a priority map:

Old Priority New Priority
5 10
6 9

And the host should pass the data like so:

ID Card Type Priority Played State Alive
6 Cyberpod Assault 7 Hand
7 Iron Maiden Assault 5 Hand
8 Lead Dozer Assault 2 Hand
13 Chainslicer Assault 6 Deck
12 Iron Maiden Assault 5 Deck
9 Chainslicer Assault 6 Deck
11 Judgement Nova Assault 11 Deck
10 Missile Silo Structure 8 Deck

Note that priority 9 and 10 no longer exist, and that duplicates for 5 and 6 exist.

Now the list is iterated over twice to emulate a draw, and on the first pass we see:

ID Card Type Priority Played State Alive
6 Cyberpod Assault 7 Hand
8 Lead Dozer Assault 2 Hand
7 Iron Maiden Assault 5 Hand
13 Chainslicer Assault 6 Deck
9 Chainslicer Assault 9 Deck
12 Iron Maiden Assault 10 Deck
10 Missile Silo Structure 8 Deck
11 Judgement Nova Assault 11 Deck

And the second pass:

ID Card Type Priority Played State Alive
8 Lead Dozer Assault 2 Hand
7 Iron Maiden Assault 5 Hand
13 Chainslicer Assault 6 Deck
6 Cyberpod Assault 7 Hand
9 Chainslicer Assault 9 Deck
10 Missile Silo Structure 8 Deck
12 Iron Maiden Assault 10 Deck
11 Judgement Nova Assault 11 Deck

Now the cards are in proper order for play, we can take the current turn from the host, which in this case is 7, and give each card it's turn ID based on turn + (thread ID - hand position * 2) . Now the cards know when they will activate.

Our new final layout would be:

ID Card Type Priority Played State Alive
0 Barracus Commander 0 Turn 0 Yes
1 Lightning Cannon Fortress 0 Turn 0 No
2 Corrosive Spore Fortress 0 Turn 0 Yes
3 Chainslicer Assault 3 Turn 1 Yes
4 Tempest Keep Structure 1 Turn 3 Yes
5 Anvil Assault 4 Turn 5 No
8 Lead Dozer Assault 2 Turn 7 Yes
7 Iron Maiden Assault 5 Turn 9 Yes
13 Chainslicer Assault 6 Turn 11 Yes
6 Cyberpod Assault 7 Turn 13 Yes
9 Chainslicer Assault 9 Turn 15 Yes
10 Missile Silo Structure 8 Turn 19 Yes
12 Iron Maiden Assault 10 Turn 21 Yes
11 Judgement Nova Assault 11 Turn 23 Yes

Now there are three re-arrangements that can be made throughout the game, two of which require a map; compression, turn ordering and wall detection.

##Compression

This is done to re-align the assaults so that they have a relative pair on the opposite side. It uses a map which is retained throughout combat. Units are sorted by living, then by assault, then by turn ID descending

##Turn Ordering

This is done once and retained in a map in order to determine the order in which units take their turns. Units are sorted by type (commander, structure, assault), then by turn ID

##Wall Detection

In order to find the latest wall, no map is required. Any unit which is a structure and has the wall skill will call the atomic max function, passing it's turn ID (if the turn ID does not exceed the current turn). Then, if the turn ID is equal to a unit's turn ID, it sets it's ID as the output. If that value has changed, there is a wall and it is used to compute the combat.