engineer-thesis-WUT/matchingLogic.txt

65 lines
1.6 KiB
Plaintext

Given a vector of n x n elements
0. simplify vector from game object to vector of unsigned int id:
GameObject:
id
texture
position
...
-> id
we get a vector:
{
0 1 2
2 1 0
1 2 0
}
1. split the vector into vertical and horizontal
vertical:
calculate square root of vector size -> thats the length of single row and column
a) split horizontaly
get first n elements -> thats first vertical
then get second n elements -> thats second vertical
...
in the end we get 3 vectors:
{ 0, 1, 2}
{ 2, 1, 0}
{ 1, 2, 0}
b) split vertically
get first element [0]
add "n" elements
get second column [n] (in our case 3)
repeat until number of column + n < n^2
increment first element by 1
go to loop start if first element <= n (3)
in the end we get 3 vectors
{ 0, 2, 1 }
{ 1, 1, 2 }
{ 2, 0, 0}
Matching logic:
1. Find matches
a) Vertical
t t t
t t t
t t t
t t
t
I)
Since we splited our vectors into vectors of ids we made our job much easier
count = 1
take first element
take second element
check if first == second
if yes count += 1
if no count = 1
take third element
check if second == third
if yes count += 1
if no = 1
if count >= 3
matchesVector.push_back(0, 1, 2)
if count == 1
b) horizontal
t t t
t t t t
t t t t t