Blackjack!
Not
Split
bet $20
bet $20
bet $20
Double down
bet $20
bet $40
public interface BotInterface {
/**
* Bet at the start of the hand.
*
* @param minimum Minimum allowed bet. If you bet less than this, your bet will
* be ignored.
* @param maximum Maximum allowed bet. If you bet more than this, your bet will
* be ignored.
* @param money Available bot funds.
* @return
*/
int bet(int minimum, int maximum, int money);public interface BotInterface {
/**
* Analyze the current hand and dealer's face up card, and return an Action.
* If you return an invalid action, it will count as standing.
*
* @param money Available bot funds.
* @param hand Bot hand.
* @param dealerFaceUpCard Dealer's face up card.
* @return
*/
Action play(int money, Hand hand, Card dealerFaceUpCard);package me.nemanjamiljkovic.blackjack.Bot;
public enum Action {
STAND,
HIT,
SPLIT,
DOUBLE_DOWN
}
@Override
public Action play(int money, Hand hand, Card dealerFaceUpCard) {
// Double down and hope for a 10...
if (hand.getValue() >= 9 && hand.getValue() <= 11) {
return Action.DOUBLE_DOWN;
}
// Split hands if the pairs are 4+
if (hand.canSplit() && hand.getValue() > 8) {
return Action.SPLIT;
}
// Hit if less than 16
if (hand.getValue() < 16) {
return Action.HIT;
}
return Action.STAND;
}try this http://bit.ly/1jyhxNv
public class Card {
public static final int RANK_ACE = 1;
public static final int RANK_JACK = 12;
public static final int RANK_QUEEN = 13;
public static final int RANK_KING = 14;
public enum Suit {
HEARTS, CLUBS, SPADES, DIAMONDS
}
public int getRank() { ... }
public Suit getSuit() { ... }
public int getValue() { ... }
}
public class Hand {
public List<Card> getCards() { ... }
public boolean canSplit() { ... }
public boolean isBlackjack() { ... }
public boolean is21() { ... }
public int getValue() { ... }
}package me.nemanjamiljkovic.blackjack;
import java.net.Socket;
import me.nemanjamiljkovic.blackjack.Bot.Communicator;
import me.nemanjamiljkovic.blackjack.Bot.SimpleBot;
public class Main {
public static void main(String[] args) {
try {
Socket socket = new Socket("blackjack.nemanjamiljkovic.me", 8000);
Communicator.createAndRun(socket, new SimpleBot());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Send your bots to
nemanja.miljkovic@devana.rs
before 1. Nov 2015.
All programming languages allowed.
PHP
Java Bot
Browser
Browser
Browser
Java Bot
Java Bot
{
"alias": "request_bet",
"data": {
"minimumBet": 50,
"maximumBet": 150,
"money": 5000
}
}{
"data": {
"money": 4692,
"playerHand": {
"cards": [{
"rank": 7,
"suit": "H"
}, {
"rank": 3,
"suit": "S"
}],
"canSplitHand": false,
"value": 10
},
"dealerCard": {
"rank": 2,
"suit": "S"
}
},
"alias": "request_action"
}JSONObject message = new JSONObject(stringMessage);
String alias = message.getString("alias");
JSONObject data = message.getJSONObject("data");
int minimum = data.getInt("minimumBet");
int maximum = data.getInt("maximumBet");
int money = data.getInt("money");{
"alias": "request_bet",
"data": {
"minimumBet": 50,
"maximumBet": 150,
"money": 5000
}
}JSONObject response = new JSONObject();
JSONObject data = new JSONObject();
data.put("amount", 67);
response.put("alias", "bet");
response.put("data", data);
response.toString(); // {"data":{"amount":67},"alias":"bet"}{
"data": {
"amount": 67
},
"alias": "bet"
}while (socket.isConnected()) {
String stringMessage = in.readLine();
if (stringMessage == null) {
return;
}
try {
JSONObject message = new JSONObject(stringMessage);
this.parseMessage(message);
} catch (JSONException exception) {
continue;
}
}
{
"alias": "request_bet",
"data": {
"minimumBet": 50,
"maximumBet": 150,
"money": 5000
}
}PHP to Java
Java to PHP
{
"data": {
"amount": 67
},
"alias": "bet"
}Betting
phase
Java Bot
Java Bot
Java Bot
Allow 3 seconds to respond
ignore the message
kick the bot
skip the round
in competition mode, kick the bot
Playing phase
phase
Java Bot
Java Bot
Java Bot
Serially communicate with bots
i.e. finish with bot 1 before communicating with bot 2
ignore the message
kick the bot
count as Action.STAND
public function startNewHand()
{
if (!$this->running) {
return;
}
$this->resetTable()
->then(function () {
return $this->requestBets();
})
->then(function () {
return $this->dealInitialCards();
})
->then(function () {
return $this->playHand();
})
->then(function () {
return $this->playDealerHand();
})
->then(function () {
return $this->distributeWinnings();
})
->always(function () {
return \Blackjack\Promise\timedResolve(self::LONGEST_PAUSE_SPEED)
->then(function () {
$this->startNewHand();
});
});
}Multiple threads
Single thread
Send your bots or questions to
nemanja.miljkovic@devana.rs