nus-gdg / TotalChess

2 stars 3 forks source link

Board State Manager #1

Open nicholaschuayunzhi opened 5 years ago

nicholaschuayunzhi commented 5 years ago

Board State Manager

Input

Output

Algorithm

Movement Check:

If units are not moving:
  record their location and remove from consideration
while there are moves to resolve:
  for each of the remaining pieces:
    if there is invalid move:
      record their location and remove from consideration
  if there was no invalid move found:
    apply all valid moves // there wont be any more moves to resolve after this

Invalid Moves:

After this we will have a resolved board state where movement has already been applied and we can infer combat information from the direction each piece is facing.

EDIT: Combat Check:

For each piece:
  identify all potential enemy attackers
  damage = based on attack
  damage dampening based on number of enemies
  multiply damage based on effectiveness (triangle)
  multiply damage based on current health (subject to unit type)
  apply final damage to all attackers
Rinder5 commented 5 years ago

Does a piece moving into a piece which stays stationary count as an invalid move?

What about if a piece is moving into a piece which is moving out of that space? Consider

1 2 3 4
B left C left

Is C invalid?

What if a piece is moving into a piece which is moving into an invalid move, is that considered an invalid move? Consider

1 2 3 4
A right B left C left

Is C invalid now?

nicholaschuayunzhi commented 5 years ago

For the first case C is valid. The fact that we remove all stationary pieces from consideration and mark their squares means we can assume that C will be moving to an empty square.

For second case C left is invalid. The algorithm would have locked a and b in their positions. When we recheck C, we see that C is attempting to enter a locked square. I think i forgot to add that moving to a locked square is invalid. Thanks for checking, will update

zxadventurer commented 5 years ago

So what happens is that the game logic will first figure out all potential movement by pointing to the square that the unit is moving into. In scenario 1:

1 2 3 4 B left C left

The game will list out all the squares a unit will move into as: { 2, 3} As there are no repeated references to a square, all moves are considered valid and executed.

For scenario 2, this is where the game processes the data in steps. So for scenario 2:

1 2 3 4 A right B left C left

The game will list out all the squares a unit will move into as: {2, 2, 3}

As there is a repeated reference, the game detects an invalid move and first consider those units as not moving. Units that do not move will refer to their current square in this system. the game re-checks the board and now the array looks like: {1,3,3}

Now there is another invalid move. the game will once again make the conflicting units not move and re-check.

{1,3,4}

The game has detected no more issues as all references are valid and will now process the initial movement commands as attacks, determining if there is combat or bounces.

nicholaschuayunzhi commented 5 years ago

Combat check has been updated based on today's discussion. Formula will be updated soon.