I have a triangular matrix with triangles that are facing upwards and downwards (I'm trying to make this)
posted 2 months ago
I accidentally pressed the Enter button while trying to insert an image of the board.
It's a Spectrangle board and I want to write an algorithm that checks if it's a valid move by matching the tiles. They have to be the same color to match.
However the upwards tiles have different array indexes than the downwards and I can't get it to work, especially when a player chooses to rotate the tiles.
Any help would be greatly appreciated.
Which is why I'm wondering whether a Pascal's Triangle might be something you could use to assign values to the points that each Tile's vertices touch on the Board. If two tiles touch the same two points on the board, then they will adjacent to each other on that edge.
On second thought, Pascal's Triangle would probably not be the simplest thing you could possibly do. I think just indexing the points on Board that the vertices will touch will be enough. Again, if two tiles touch the same two points, then that would mean they're adjacent along the edge defined by those two points.
This is actually an interesting exercise in assigning responsibilities to objects and following the Tell, Don't Ask Principle
I would index the points where the vertices of the tiles touch, not the spaces on which the tiles are placed, which is probably what you're thinking, Campbell. If you look at the points, Pascal's Triangle fits fine. However, I still think that's overkill.
Wow, thank you guys for the ideas. I'm just a beginner and not really good at math, so I just thought I'd hardcode everything... But, when a player chooses to rotate a tile to match the existing ones, the array gets messed up and if the field is upwards, then the left color should match the right color. Ahhh... too much. But thank you.
This seems like a really good exercise in object-oriented programming. You could write a procedural solution to this but I think an object-oriented solution will be much better organized and easier to understand. I don't know if you are equipped to be able to come up with an OO solution though. Seems like most students are taught to think in a very procedural-minded way even when they are learning how to program with Java.
Yeah, I agree... I've now created methods that first check if a field has a neighbor and then different methods that return that neighbor.
Then, I will create more methods to check if each color matches their neighbor's individually and after rotation, as breaking down things is easier for me to understand. I know this is a noob approach but I'm just trying my best. If you think this is a really bad thing to do, I'm very open to any different approaches.
I would probably stick to a Field array, with 9 rows and each row[i] being of length 2 * i + 1. A Field with even column coordinate would be in BaseDown state, else BaseUp.
My Tile class would have a List of neighbor Fields, all determined at initialization.
Just a quick question:
I just read on Wiki that there are 35 colored Tiles (called trangs) plus a white one, consisting of all the permutaions of three colors out of five. If I calculate what that means, I get:
1) there are 10 permutations of 3 out of 5 colors. Each permutation comes in 6 variants (1,2,3), (1, 3, 2) et cetera. But three of these can be obtained by rotating the tile, so in fact there are ony two different parmutations: 1, 2, 3 and 1, 3, 2. But these can be put on both sides of a Tile, so we need 10 of these Tiles alltogether.
2) there are 20 permutations of two identical and one different colors (112, 113, ..., 554), 20 of them, making 30 Tiles so far
3) and there are 5 Tiles that have three equal colors: 111, 222, ..., 555.
Am I right? If so, it means that the permutations 123 and 132 are mutually exclusive, since you can use a Tile only once in the game, with either front or back facing up.
I was wondering along the same lines as Piet. It's not actually permutations because that would mean order matters. In reality, you have 35 combinations of 5 colors taken 3 at a time. The 36th trang is the all-white "joker" trang which will match any tile(s) it is placed next to.
5 colors: Red, Green, Blue, Magenta, Yellow
5 trangs that have all three segments of the same color
5 x 4 trangs that have two color: one color for the base and another color for the two sides
# combinations for 5 colors taken 3 at a time: 10
So, 5 + 20 + 10 = 35
Again, the 36th tile is the all-white joker trang.