Sandbox notes
- This is the first time I write a controller; and it's been a while since I wrote an actual program. If you feel so inclined, feedback is appreciated.
Initial draft of the controller (java) here: https://github.com/S119349/cooperative-koth
king-of-the-hill card-game java
In this king-of-the-hill challenge, instead of competing, players will have to work together to beat a game. The player who on average gets the best results over all game runs, is the winner for this challenge. The game is inspired on the mechanics of "The Game".
Game mechanics
The goal of the game is to play as much cards as possible on four piles on the table. Two piles can only accept cards in strictly increasing order, the other two in strictly decreasing order. The game is over as soon as a player cannot play a card.
Piles
The game starts with four piles, numbered 0 through 3 inclusive. Piles 0
and 1
accept cards in strictly increasing order; piles 2
and 3
accept cards in strictly decreasing order. Initially, the piles are
Pile number | 0 | 1 | 2 | 3 |
Card | 1 | 1 | 100 | 100 |
There is an exception to the rule of accepting only strictly increasing/decreasing order. You are allowed to play a card exactly 10 less or more respectively than the current card. For example, if the piles are
Pile number | 0 | 1 | 2 | 3 |
Card | 1 | 32 | 78 | 100 |
you are allowed to play 22
on pile 1
, or 88
on pile 2
.
Taking turns
The game starts with a shuffled draw stack containing 98 cards, numbered 2 through 99 inclusively. Each player is dealt 6 cards at the start of the game. The cards are known only to the players themselves.
During a turn, a player must play at least two cards Exception: you only have one card, or you're out of cards, because the draw stack is empty, up to all the cards in their hand. After their turn, the player will restock from the draw stack to 6 cards (or less at the end of the game).
Reacting
After each card is played, other players are allowed to react: if you have the perfect card in your hand, you may want to warn players not to add anything to that pile! Since your cards are secret to you, this is done by assigning priorities to each pile. The priority is from 0
to 5
inclusive, with 0
signifying no interest at all in that particular pile, and 5
begging other players not to add anything to that pile. Other players can use these priorities as they deem fit; including completely ignoring it.
Interaction with the controller
You will create a player that extends
the abstract Player
class. You will have to implement void turn()
(for playing a card) and int[] react()
(for announcing your priorities). A reference implementation, SimpleTom
, is provided, but may be removed from the competition if there are enough competitors.
In void turn()
, you are required to either playCard(int card, int pile)
or endTurn()
. Note that you may only play one card per invocation of turn()
, to give other players an opportunity to react()
. Doing anything else (playing two cards, playing no cards at all) will result in losing the game, with all the cards still in the game adding towards each player's score!
In int[] react()
, you are required to return an array of your priorities on each pile. An example would be return new int[] {a, b, c, d}
with a
through d
the priorities for each pile. Here, 0 <= a <= 5
.
To see what is happening, you have access to some members
ArrayList<Integer> hand
contains all cards currently in your hand.
- In the
gameState
member of the default Player
class:
int [] gameState.piles
contains the four piles. It is an integer array of size 4, with each element the last played card on that pile.
Map<Player, int[]> gameState.priorities
. A map containing the latest priorities issued by each Player
in the game.
Player[] gqameState.players
can be used to list all the players in the current game; as well as determine how many cards they have by calling int nHandCards()
. Note however that you may not access these players
in any other way! (force them to do a turn, force them to lose, make them expose their hand, etc).
Concerning the other players: you may know who is playing and assess their skill during a game (for example, figure halfway through a game that SimpleTom
is not trustworthy, and that two of the other players are of type SimpleTom
). You may not save this information between games, or hard-code strategies concerning other players.
Do's and don'ts
All entries are open-source. You are encouraged to write commonly used functions (e.g., something to keep track of what cards have already been played) as separate functions, so others may use them. When you use code from others, always attribute your source. It is not OK to copy someone's algorithm and just tweak a few values - your code should be significantly different from others.
You are allowed to use a different languages than Java, if you write your own wrapper class (or use someone else's wrapper class). I usually only use Try it Online!, so I don't have any compilers installed on my Ubuntu box. If you use another language that is not available on Ubuntu by default, please include a few lines on how to install your language. Your entry will be non-competing if it takes me more than two minutes to follow these instructions, so a script or copy-pasteable command line code is preferred.