Hello, I'm back from a long hiatus!

My dad is working on a board game where players place hex tiles on a blank board until there is no more legal placement (disregarding scoring here).


The rules are simple:
There are eight different types of hex tiles:
note: pips are on corners and bars connect the pips in a continuous line
note 2: each player has two tiles of each type, but no player possesses the blank tiles as this is placed at the beginning of the game

> blank (there are two of these in the game set)
> one pip
> two pips with one bar
> three pips with two bars
> four pips with three bars
> five pips with four bars
> six pips with five bars
> & six pips with six bars


The starting board:

Two blank tiles placed next to each other


Legal placement:

legal placement is when bars are touching and pips are touching between any number of tiles. the only exception to this rule is, at the beginning of the game any tile can match with any blank tile, assuming that no non-blank tile makes the placement not legal (see the first rule).


For example:

EX 1: a one pip tile and another one pip tile can only be legally placed if the pips on the corners are touching
EX 2: a one pip tile and a six pip, six bar tile will not be legally able to be placed, ever (assuming these are the only two tiles on the board).
etc, etc.


My problem is, that I want to make a Mixed C++ and Obj-C program, (written in Xcode), that calculates all possible board setups.

Now, I'm not the best in the programming department, so I need some guidance

I was thinking nested if's and switch-cases in objective-c, that tests if each placement iterated, would be legal. This file would be linked to a main.cpp that iterates through every tile possible until there is a legal placement. The tile placed would no longer be able to be placed (as it is no longer in the player's hand).

The only problem with this is that this code would be long and yanderedev-ish, and unreadable.

Is there a better way of doing this?

I've done some research and I could write a parser, but I've only found tutorials for parsing files, not possibilities.


Thank you for your time reading this L.L
Quote:
I was thinking nested if's and switch-cases in objective-c, that tests if each placement iterated, would be legal. This file would be linked to a main.cpp that iterates through every tile possible until there is a legal placement. The tile placed would no longer be able to be placed (as it is no longer in the player's hand).

The only problem with this is that this code would be long and yanderedev-ish, and unreadable.

The amount of repetitive code required for this would be so long that you would probably need to write a program to write the code for you, which is basically equivalent to just solving the original problem.

Quote:
I've done some research and I could write a parser, but I've only found tutorials for parsing files, not possibilities.

Parsers are usually used to convert text into a computer-readable format. More generally, parsers interpret an input that's formatted according to a formal grammar, which I don't think is present for this problem. So, if you were to make a parser for "possibilities," I think that by definition it would stop being a parser.

Do you have any pictures of the tiles? That might make it a bit easier to visualize the problem.
If I understand it correctly, it sounds like it's impossible to get into a situation where the pip requirements are met for placement but not bar requirements, as a bar always connects two pips.

If I were just trying to create a working product (as opposed to one that runs efficiently) I personally would approach the game like this:
Create a hex grid that represents the game state - you can give each tile a unique X, Y position by looking at only two of the three "axes" tiles are on.
Represent each tile as a list of bools, one for each corner of the hexagon, that is true are a pip is there - to rotate it, take the first element out and replace it at the end, or vice versa.
When trying to place a tile at a particular location and rotation, look at each of the neighbors, and check the two corners both hexagons share. If one hexagon has a pip in the corner while the other doesn't, then the placement is invalid. If none of the neighbors included a corner with a pip, then the placement is also invalid.

Without playing a few games myself, I'm not sure how feasible it would be to get the full list of possible layouts - it depends on the average number of valid moves each turn. Some back of the napkin math: if there are 28 moves, if you only have one possible move per turn, there would be only one game layout. With two possible moves per turn on average, there would be around 2^28 (268435456) layouts, which is feasible to calculate exhaustively. For three, there would be about 3^28 (22876792454961). For four moves per turn, there would be around 4^28 (72057594037927936) possible layouts, which would take an absurd amount of time to compute.

I still think this is an interesting project even if it's not possible to get a full list - maybe you could make an AI for the game if you get the scoring implemented, which would basically the same thing, except it would require much less computational power since you only have to look ahead a few moves rather than 28.
CBG wrote:
The amount of repetitive code required for this would be so long that you would probably need to write a program to write the code for you, which is basically equivalent to just solving the original problem.

any idea how i can get started on this? I consider myself pretty well versed in unix shell scripting languages that are bourne-based, would that work?

CBG wrote:
Do you have any pictures of the tiles?



CBG wrote:
If I understand it correctly, it sounds like it's impossible to get into a situation where the pip requirements are met for placement but not bar requirements, as a bar always connects two pips.

it is possible (in specific cases )
for example :

html load image

CBG wrote:
Create a hex grid that represents the game state - you can give each tile a unique X, Y position by looking at only two of the three "axes" tiles are on.
Represent each tile as a list of bools, one for each corner of the hexagon, that is true are a pip is there - to rotate it, take the first element out and replace it at the end, or vice versa.
When trying to place a tile at a particular location and rotation, look at each of the neighbors, and check the two corners both hexagons share. If one hexagon has a pip in the corner while the other doesn't, then the placement is invalid. If none of the neighbors included a corner with a pip, then the placement is also invalid.

The problem is with this method, is that the board isn't a "set" size. The "board" is actually a big table. I guess I could implement it in Objective-C's functionality with dynamic array size? (I think Obj-C does that?). Correct me if I'm wrong
Izder456 wrote:
CBG wrote:
If I understand it correctly, it sounds like it's impossible to get into a situation where the pip requirements are met for placement but not bar requirements, as a bar always connects two pips.

it is possible (in specific cases )
for example :


Ah, I misunderstood. So, in that image, it would be invalid to play the right tile and then the left, but would be valid to play the left and then the right?

So, the method I suggested would probably still work, you'd just have to add additional checks for bars.

Quote:
The problem is with this method, is that the board isn't a "set" size. The "board" is actually a big table. I guess I could implement it in Objective-C's functionality with dynamic array size? (I think Obj-C does that?). Correct me if I'm wrong

Although there's technically not a limit to the game board, in practice, since there are only 28 tiles, a (28*2+1) by (28*2+1) board would be enough that even if you put the tiles down all in a straight line, you wouldn't be able to go past the edge of the board. You could also use a mapping structure like a dictionary or a btreemap or whatever, but that would be slower and there's not much benefit to it, since the size is limited.

Izder456 wrote:
CBG wrote:
The amount of repetitive code required for this would be so long that you would probably need to write a program to write the code for you, which is basically equivalent to just solving the original problem.

any idea how i can get started on this? I consider myself pretty well versed in unix shell scripting languages that are bourne-based, would that work?

I'd strongly recommend against doing this - in C++ (and presumably objective C) pretty much anything that can be done by generating code using code can be done at runtime. This means you don't have to deal with bash, you don't get crazy filesizes and compile times, and you don't have to regenerate all of the code each time you change something.
CBG wrote:
So, in that image, it would be invalid to play the right tile and then the left, but would be valid to play the left and then the right?

idk where you got the order stuff, but any order would be legal

CBG wrote:
Although there's technically not a limit to the game board, in practice, since there are only 28 tiles, a (28*2+1) by (28*2+1) board would be enough that even if you put the tiles down all in a straight line, you wouldn't be able to go past the edge of the board. You could also use a mapping structure like a dictionary or a btreemap or whatever, but that would be slower and there's not much benefit to it, since the size is limited.

the problem is with that again is that there are 5 max players (with expansion pack that adds another player), so, that brings a total of (14_PlayerTiles*4_players)+(2_BlankTiles) = 58 max (x || y) dimension, in a non-expanded game. so do I make a 58x58 array and hog memory like I hog my calculators? no. (jokes?). what can I do to avoid having such a massive array?

CBG wrote:
I'd strongly recommend against doing this - in C++ (and presumably objective C) pretty much anything that can be done by generating code using code can be done at runtime. This means you don't have to deal with bash, you don't get crazy filesizes and compile times, and you don't have to regenerate all of the code each time you change something.

I've actually never done this. Any help with this would be nice. (still somewhat new to compiled languages)
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement