farin / JCloisterZone

Java implementation of Carcassonne board game
https://jcloisterzone.com
MIT License
305 stars 100 forks source link

Prepared Games #77

Closed Decar closed 7 years ago

Decar commented 9 years ago

Some people at carcassonne-central suggested a new feature; basically allow people to prepare the tiles to use in a game, so that the order of the tiles is pre-determined. This can be used to set up puzzles for users to load into JCZ and determine the 'best' strategy for a match. When the list of prepared tiles is completed, the game should either end or continue at random, determined by the puzzle creator.

Such a feature would need:

I've made a start at implementing these features at https://github.com/Decar/JCloisterZone/tree/prepared-games

Defining a draw sequence

Currently, it seemed logical that a puzzle creator loads a YAML file (such as prepared.yaml) to define the draw sequence and discarded tiles, this is essentially the same as the debug operatives currently in place:

draw:
  - BA.RCr
  - BA.C
  - BA.CccR
  - BA.Rr
  - BA.Ccc+
  - CA.Cc+
  - AM.C!+
  - .    #A Dot should indicate that the game ends at this point.
discard:
  - BA.L
  - BA.Lr

I've created a PreparedGameConfigLoader and PreparedGameConfig to load the yaml file into an Object which can be used every time a game is started.

Loading YAML file into PreparedGameConfig

The PreparedGameConfig should be created at the start of every game, unlike the existing Config which loads when JCZ starts. I think it makes sense to add a preparePreparedGame method to the CreateGamePhase, as other game components are set up at this time.

Saving the game state

I think it's important to indicate that the Game is now a Prepared Game and that this is recorded in the Snapshot XML. It seems logical that the snapshot contains the list of remaining prepared tiles left to play, so that someone completing the puzzle does not need to mess about with configuration files. Just load the save file:

Here's a proposed example save file:

...
<game app-version="dev-snapshot" phase="com.jcloisterzone.game.phase.TilePhase" prepared-game="true">  ###A new value for prepared
...
<tiles next="BA.CccR">
...
<prepared name="BA.Rr"/>  ###A record for each prepared tile remaning
<prepared name="BA.Ccc+"/>
</tiles>
</game>

Drawing a Tile

Currently the number of the next drawn tile is determined in the SimpleServer class in the handleGetRandSample method and this fires an event which is read by the DrawPhase.

Yesterday, I swapped out the DrawPhase with a PreparedDrawPhase, but now I see that the Tile ID should be determined by the SimpleServer. This is a much simpler solution. What I'm not clear about is what should happen if the game ends early; but the DEBUG code should provide a clear enough example.

Displaying a Prepared Game

I think it makes sense to include a new value on the right hand side to indicate the number of prepared tiles left in the deck; it will be clear to someone playing that the Game is of a different type.

Decar commented 9 years ago

I see a small problem with implementing the DrawTile Logic on the SimpleServer - The Class RandSampleMessage uses int[] to tell the DrawPhase (and BazzarPhase) which tile should be drawn.

This will need to be overloaded to support String[] so tileIDs can be used. This will have a knock-on in the DrawPhase when msg.getValues()

This seems like the way to go; is there any preference in the array type used?

farin commented 9 years ago

@Decar just short answer now - you can use TilePack and track current tiles and their indexed inside server - (just simply resuse client side impl) then you can ask what "random id" is needed to draw wanted tile.

btw look at play-online branch, it has little different messaging and especially draw tile is different. play-online is current 3.1 dev branch and i try to merge it to master during weekend

Decar commented 9 years ago

Thanks for the help @farin, I've had a quick look at the new online-play branch. I can see that handleMakeDraw contains the new tighter implementation.

I hadn't realised I could get the "random ID" for a given Tile ID. I'm having trouble finding it, unless I implement a new method like getIndex, which seems simple enough.

It's probably best to wait until your merge is completed, I'm a little confused because currently SimpleServer doesn't seem to have scope to the game-package, so SimpleServer can't see the TilePack. I thought that was by design. I'd appreciate your advice when you have chance.

Good luck with the merge!

Thanks again.

farin commented 9 years ago

About other features then draw order: A mechanism for the puzzle creator to define a list of discarded tiles. Make sure that the list of tiles is stored, so that puzzles can be saved and loaded by users. Make sure users are aware of the number of perpared tiles in the deck.

I think the best way is change new game / save game format - because I want to do be able support more custom combinations of expansions - like two sets of basic exp etc. It is not big deal to allow go down to tile level and specify any number of any tiles additionally.

But it is question how to show what user can expect in tile pack (in such case there are not discarded tiles) - but even for multiple expansion i think it will be needed add some hint view to show what is in the pile.

Decar commented 9 years ago

I wondered if there needs to be some sort of refactor of the TilePack, so that the available tiles is determined at the start of the game and stored in the Save file. Perhaps this can be an ordered list too that way the same TileDeck could be used for Random and Prepared Games, for any number of tiles.

I've wanted to be able to see the remaining tiles in a Deck (to aid card counting); this could be achieved like the Discard Pile, but utilizing the TileDeck's remaining cards.

Decar commented 9 years ago

Created a RemainingTilesDialog and added a method to the DefaultTilePack to return all tiles.

Currently, looks like this: jcz_remaningtiles

I think this will help, show user's what tiles to expect. re: prepared games, I think it can easily put the prepared tiles at the top.

It's worth considering Hill & Sheep expansion which introduces the idea of unknown discards.

x-iso commented 9 years ago

Yes, list of remaining tiles should be an option for a game setup. Can be helpful and evens out a bit strategy level of newbies and experienced players.

farin commented 7 years ago

possible by annotatons section in saved games

see integration test which in common use "prepared games" wth defined tile order eg https://github.com/farin/JCloisterZone/blob/master/src/test/resources/saved-games/inns_and_cathedrals/cathedralsScoring.jcz