- Need help avoiding nested if conditionals and switch-case's
- 27 Jan 2021 05:49:14 pm
- Last edited by Izder456 on 27 Jan 2021 10:09:16 pm; edited 1 time in total
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
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