Pokerface
Introduction
Leo enjoys playing poker, but his job at Tech Inc. is too demanding for him to learn how to play well. Leo, being a computer scientist, is not discouraged. He decides to take more time than it would have taken to just learn poker, and use it to write a poker bot to help him play better. But now Leo has a problem: in order to understand how to play a bit better, Leo needs to observe multiple games of multiple "people," but the "people" need different play styles to improve the quality and reality of the game.
The Challenge
Leo recalls that there is actually a website dedicated to programming challenges, and is enlisting your help! Your job is to write a program which plays "Pokerface" a modified version of 5-card poker. The program will take input as a 5-card hand in whatever format you wish, after which the program will output:
- Exactly (case-sensitive) "true" "1" or "t" if the player wishes to exchange cards, any other non-empty output otherwise.
- If true, list of indices of cards and/or card names the player wishes to exchange.
- A single number between 0 and 3, which specifies how many additional cards the player wants.
- Print out the hand the player wishes to use.
(See formatting below)
Pokerface rules
- Since pokerface is a text-based adventure game, cards must be presented in a consistent way. Cards are represented by two character codes, the first character is the suit, and the second is the name of the card.
- Cards:
- 2-9 = 2-9
- 10 = T
- Jack = J
- Queen = Q
- King = K
- Ace = A
- Suits:
- Spades = S
- Clubs = C
- Hearts = H
- Diamond = D
- Cards:
So the ace of spades would be SA, the 10 of hearts is HT, the 4th of diamonds is D4, etc.
- A single round of Pokerface consists of four steps:
- The deck is reshuffled and a five card hand is dealt to each player.
- Each player is given the chance to exchange as many cards as they want.
- Each player is given the chance to gain up to three more cards.
- Each player must reveal their best hand.
- The best hand wins, and gains that player a point. In the event of a tie, both players get a point.
- In a single game, ten rounds are played and the player with the most points wins and gains a single "win point." In the event of a tie, both players gain a win point.
- Leo doesn't really have a large amount of money, so your bot can assume that this is a perfect world with no betting.
Hands
- Hands are exactly 5 cards in length (initial input and final output).
- Hands are ranked consistent with the rules described here.
Input / Output
- Leo only knows Java, so your program must be executable via the Process API (command line), and use STDIN and STDOUT for input and output, respectively.
- For each step of input and output detailed above, the input and output must each exist on one line.
- There must be at least one trailing new line after the final output. (This is due to the way input is read from STDIN)
- No extraneous input/output is allowed, other than trailing and leading spaces. The parser simply does not understand things like
final_hand=...
ordraw 0
. - When drawing, output is a single integer, when exchanging output is a list of integers and/or cards defined below, and when being dealt the original hand, output is a list of cards defined below.
- All input/output numbers must be positive integers in base 10.
- You may define the format for card input (see post format below).
- True is defined as exactly "true," "1" or "t" and false is any other non-empty value.
- During the exchange step:
- Card indices must be output with at least one space between them (e.g.
3 4 0
) - Card names must be output with at least one space between them (e.g.
H4 S8
) - Card names and indices may be mixed in the output (e.g.
0 H7 3 D3
) - Trailing and leading spaces are allowed.
- The input as a result of the player outputting the above will be formatted as specified by the
bot.jlsc
file, in the same order as requested
- Card indices must be output with at least one space between them (e.g.
- The number of cards a player wants to add to their hand can have leading and trailing spaces.
- Hands must be output with at least one space between them (e.g.
H4 D5 CA
), trailing spaces and leading spaces are allowed. - Hands do not need to be output in proper order (e.g.
H4 D4 C4 DA SA
andH4 DA D4 SA C4
both represent 4, 4, 4, Ace, Ace, which is a full house). - If you wish to build a strategy by analyzing opponents hands, you may store data in a
<botname>/data
directory.- After competing bots have displayed their hands, they will be written to every bots data directory, in hands.txt, with each hand on a new line (separated by \n). The file will be encoded in US_ASCII.
- After your bot requests new cards or exchange cards, the cards will be input depending on what format you specify in the
bot.jlsc
file.
Post Format
- Every post must include two things:
- The source code of your bot, or a link to a public facing repository.
- A zip file containing:
- The compiled/executable version of your bot (If the file is a .exe or other non-de-compilable file, please just include compilation instructions in your post).
- A
bot.jlsc
file, see below (side note: the .jlsc extension is just because of a side project of mine, a configuration format. The file below matches the proper syntax, so don't worry).
- The .zip file must be named the same as your bot.
- If you don't have access to windows or some other zipping utility, or can't make a .zip for whatever reason, just include the text of the bot.jlsc file in your post
bot.jlsc file:
name= "Botty"
link= "example.com"
cmd= "java -jar Botty.jar"
input_hand= "${0} ${1} ${2} ${3} ${4}"
input_1= "${0}"
input_2= "${0} ${1}"
input_3= "${0} ${1} ${2}"
input_4= "${0} ${1} ${2} ${3}"
Where:
- "cmd" is the windows command line command to run your bot. Note that your bot will be in directory
<botname>
, so adjust the command accordingly. - "name" is the name of your bot.
- "link" is the link to your answer, you'll have to edit this in after posting.
- "input_hand" is how you want the original dealing to be formatted (with ${#} representing cards 0-4).
- "input_1" is how you want the input of one additional card to be formatted.
- "input_2" is how you want the input of two additional cards to be formatted.
- "input_3" is how you want the input of three additional cards to be formatted.
- "input_4" is how you want the input of four additional cards to be formatted.
Specifics
- These loopholes are disallowed (see 'common pitfalls')
- You may not write a bot the will always output the best hand possible, every time, within the rule set. (i.e. no long-running brute-force bots, nothing should be quite as 'good' as LeoBot)
- Your bot should run in ~100 ms or less (Lenient on this point, max of ~1 second)
- Any output of the bot after its chosen hand will be ignored.
- Standard loopholes are disallowed.
- Yes, I know linux is better, but I have a windows PC, so be sure the compiled/executable version of your program can be run from the windows command line.
- I already have python and java installed on my computer, but I'm willing to update to new versions and install other environments, so please specify what type of environment your program requires.
- You may not write a bot which does the same thing as another bot in every case. Spam bots are allowed, but discouraged.
- Your bot may only use cards it has. Cards lost through exchange or not dealt to begin with are invalid output in the final hand.
- Input and output may only contain ASCII characters.
Tournaments
- Tournaments will be run when I get the time (my schedule is nearly as packed as Leo's, so this my be a little infrequent. Sorry for the inconvenience.).
- Bots will be pit against eachother in 4 person games, and there will be one game for each possible subset of bots (i.e. lots of games).
- This process will be repeated five times.
- Due to the way the tournament handler makes the groups of bots, up to three filler bots will be added to make the number of bots divisible by 4. These bots will simply return the hand they were originally dealt.
- After every round and game is run, the scores of the bots will be computed based on the number games they won.
- Multiple bots can share a position (ties for first won by first posted).
- After a tournament finishes, the scores will be appended to the bottom of this post.
Scoring
Normal KoTH rules. The bot(s) that win the most games win the challenge.
LeoBot
Leo's bot is pretty smart. It doesn't exchange any cards, that's too hard, but it does request the maximum number of additional cards, and it determines the best possible hand it can make, and plays that hand. The main logic of leobot is below.
package com.gmail.socraticphoenix.pokerface.leobot;
import com.gmail.socraticphoenix.pokerface.lib.card.Card;
import com.gmail.socraticphoenix.pokerface.lib.card.Deck;
import com.gmail.socraticphoenix.pokerface.lib.rule.HandRegistry;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class LeoBot {
public static void main(String[] args) {
List<Card> hand = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
hand.addAll(Card.parseHand(scanner.nextLine()));
System.out.println(false);
System.out.println(3);
hand.addAll(Card.parseHand(scanner.nextLine()));
List<List<Card>> possibleHands = LeoBot.getSubsets(hand, 5);
System.out.println(Deck.toString(possibleHands.stream().sorted((a, b) -> HandRegistry.determineWinner(b, a).comparable()).findFirst().get()));
}
private static <T> void getSubsets(List<T> superSet, int k, int idx, List<T> current, List<List<T>> solution) {
if (current.size() == k) {
solution.add(new ArrayList<>(current));
return;
}
if (idx == superSet.size()) return;
T x = superSet.get(idx);
if (!current.contains(x)) {
current.add(x);
}
getSubsets(superSet, k, idx + 1, current, solution);
current.remove(x);
getSubsets(superSet, k, idx + 1, current, solution);
}
public static <T> List<List<T>> getSubsets(List<T> superSet, int k) {
List<List<T>> res = new ArrayList<>();
getSubsets(superSet, k, 0, new ArrayList<T>(), res);
return res;
}
}
Note that if LeoBot consistently wins the tournaments, and there are a good amount of entries, I'll stop including him in the running.
Important Links
Disclaimer
Leo and Tech Inc. are story elements and any resemblance to real-life companies or people is purely unintentional. (However, when Leo's 'situation' adds or subtracts conditions from the question, those are actually part of the question...)
"f"q+
fulfils minimum requirements. If there are 10 people in competition, this probably beats all non-dumb entries (non-dumb entry probably has >75 chars, 5*10(score of dumb bot, coming last)=50<75 (score of very small smart bot (coming first))). Thusly, you should probably remove codegolf from this challenge \$\endgroup\$