I started to make a simple domino game. (the one where you place the tiles with same numbers next to each other). I started modelling it and i seem to have landed in a tough spot now. Im modelling the actual domino (called "bone"):
namespace DominoCore
{
public enum BoneOrientation { Horizontal, Vertical }
public interface IBone
{
int FirstValue { get; }
int SecondValue { get; }
BoneOrientation Orientation { get; set; }
}
}
After this type I need to lay them out on the playing field. I made a playing field with square tiles in it:
namespace DominoCore
{
public interface IField
{
IPlayer FirstPlayer { get; }
IPlayer SecondPlayer { get; }
IBoneYard BoneYard { get; }
List<ITile> Tiles { get; }
void PlaceBone(IPlayer player, IBone bone, int startX);
}
}
The playing field has two players and a Boneyard (the dominoes not given to players) and then a list of tiles.
namespace DominoCore
{
public enum BoneExpandDirection { Up, Down, Right, Left }
public interface ITile
{
int X { get; }
int Y { get; }
IBone Bone { get; set; }
BoneExpandDirection ExpandDirection { get; set; }
}
}
Now comes my problems:,
I guess at some point I need to figure out, when a player places a tile - to calculate if its legal (search the field for tiles/bones). The various placements of the same domino /bone is shown in image below.
The next problem is laying out the dominos/bones, I am thinking about making a grid, but that doesnt fit with placing a tile "across" (perpendicular) other dominos/bones. When placing a tile I'm back at the first problem: how to validate it its legal? how to find the domino it borders with?
Hope this is making sense - I find it hard to describe the layout and the validation problem im facing.
EDIT When starting the game the Bones in play are:
[6,6] [6,5] [6,4] [6,3] [6,2] [6,1] [6,0]
[5,5] [5,4] [5,3] [5,2] [5,1] [5,0]
[4,4] [4,3] [4,2] [4,1] [4,0]
[3,3] [3,2] [3,1] [3,0]
[2,2] [2,1] [2,0]
[1,1] [1,0]
[0,0]
Each tile can be reversed this means that tile [6,3] can also be flipped 180 degrees and used as [3,6]
It seems like your grid should have a minimum resolution of .5*(length of short side), assuming the length of the Bone's long side is a multiple of the length of the short side. This will allow for all sorts of different shape configurations such as scenario C.
To say it a different way, use a square grid and then overlay 2x4 size Bones on that grid.
Next you should come up with a convention for marking the location of the Bones, such as the upper left hand corner. For instance, a Bone with coordinates (3,3) and vertical orientation could refer to a 2x4 vertical Bone whose upper-left most tile lies at (3,3) on the board grid. The Bone would extend out to (4,3) on the right, and (3,6) and (4,6) on the bottom.
You would then need to run some validation after block placement to ensure that the Bone doesn't exceed the right or bottom edges of the game board.
I don't know the rules of the game, but it might help to keep an IsFlipped bool property which would display (1,3) differently (1 before 3 or vice-versa) without changing the internal representation of the Bone's values.
As far as scoring, you could maintain some information about which Bones are linked to others within your Bone implementation, and use that information to either keep a running tally of scores as blocks are placed, or have some other ruleset object that can consume a list of Bones and caluclate a score at any time.
What about linking the bones together?
public interface IBone
{
int FirstValue { get; }
int SecondValue { get; }
BoneOrientation Orientation { get; set; }
IBone left { get; set; }
IBone right { get; set; }
IBone upper { get; set; }
IBone lower { get; set; }
}
In order to determine the coordinates of the bones, you would then need a recursive algorithm in order to traverse this tree-like structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With