Hack League

Coding Battle – Cognitive Services

30th November 2016

In partnership with

Microsoft

The Game

You’re taking part to a card game. You’ll be playing against other players (bots) whom you’ll have to defeat.
You’ll receive an boilerplate with a simple AI. Improve it and defeat the other players!

How? By using the Emotion API from the Cognitive Services, you’ll be able to understand the other players’ strategy & game play.
Build your own player accordingly.

Step1: Integrate the Emotion API to retrieve the data and build your strategy to beat the first player.
Step2: Play against the other players, detect their strategy and build your player’s AI accordingly. (you’ll get the emotion API data directly. No need to use the images).

Rules of the Game

Each player starts with 10000$. The goal of the game is the same as any money game : earn as many money as possible.
Each turns starts with both player paying the blinds : 1$. Each player gets a card labelled from 1 to 1000 (each value is unique, so your opponent cannot have the same value as you get).

Each player will play one after each other the same way a poker game is played :

– The first player decides to bet, or check.
– Then the other player decides to raise, follow, or fold.
– Then the first player plays again : raise, follow, or fold.
– The the second player again…
– …
– Once a player as followed, the bets are equals for both player and the cards are revealed. The player with the highest value wins the pot.
– If a player folds, the other one wins the pot directly, and the cards are not shown.

During the game, you will get two inputs before each of your moves :
1. The state of the game : Your card, your opponent’s current bet and yours.
2. A picture URL of your opponent with its facial expression, or some data depicting the emotions of your opponent.

Here is an example
– You get the card 439. You pay the blinds as the opponent. The pot is 2$.
– You play first. You decide to bet 10$. The pot is 12$.
– Your opponent decides to raise. He follows your 10$ and bets 5$ more. The pot is now 27$.
– You decide to follow, so you pay the missing 5$. The pot is 32$.
– Cards are shown. You have 439, your opponent has 401. You win the pot.

The challenge is to code your bot according to the emotions the API has detected, and use that model to estimate the real strength of his hand.

Be careful! Your opponents will not play the game the same way.
Some will always have a face according to the value of their card, some will always have a so-called “Poker face”, showing nothing of interest, some will always try to bluff, some won’t…
Suggested strategy : you won’t be able to tell whether your opponent is a bluffer or not, at least during the first game. You should improve your model over the differents plays to get better and better again an opponent over time. Like in a real Poker game.

An API key will be provided by Microsoft on the Slack channel if you don’t have one.
We provided you a boilerplate in Node.js and another in C#. You can find them there :
https://bitbucket.org/obourdoux/hackleague-cb2016-11-30-boilerplate/src

API endpoints
The server always returns the same payload at each call :

 
{
	gameId: 123456,
	state: {
		opponentId: 123456,
		//If turn == 0, you can CHECK (ie. BET 0)
		turn: 0,
		gameOver: false,
		yourMoney: 10000,
		opponentMoney: 10000,
		yourCard: 123,


		//Amount in the pot
		pot: 123, 


		//Amount that you have to pay to follow	
		priceToFollow: 123, 


		opponentFace: <”url” | emotion_json>,
		opponentAction: ,
			bet: 1233, //Only if type == ‘BET’
		}>,

		//Results of the previous round.
		lastRound: 
		}>
	},
}

The emotion_json in opponentFace is defined as follows :

{
    "faceRectangle": {
      "left": 488,
      "top": 263,
      "width": 148,
      "height": 148
    },
    "scores": {
      "anger": 9.075572e-13,
      "contempt": 7.048959e-9,
      "disgust": 1.02152783e-11,
      "fear": 1.778957e-14,
      "happiness": 0.9999999,
      "neutral": 1.31694478e-7,
      "sadness": 6.04054263e-12,
      "surprise": 3.92249462e-11
    }
}

The sum of the scores is always equal to 1.

The gameOver flag will be set to true :
If you don’t reply in the next 30 seconds (see /play)
If you or the opponent reaches 0$ after a round (so he/you cannot pay the next blind)
After 20 rounds

IMPORTANT In evaluation phase, the opponentId will change over time, to simulate multiple games. Make sure to read it from the returned payload if you use it in your code (and you should 😉 ).

POST /api/newgame
Create a new game. This should be called before anything else, and only once.
Payload :

{
	opponentId: <1 -> 5>,
}

POST /api/evaluate
Evaluate your bot. Call this instead of /api/newgame to play against all the opponents one by one and record your score.
Payload :

{
	teamName: “YOUR_TEAM_NAME”,
}

POST /api/play
Endpoint for your bot to play. If you follow or fold, new cards will be distributed automatically and your blind will be put in the pot.

Payload :

{
	gameId: 123456,
	action: { 
		type: <‘CHECK’ | ‘BET’ | ‘FOLLOW’ | ‘FOLD’>,
		//Only required if type==‘BET’
		amount: 1233, 
	}
}

The presentation