luna_
luna_

Reputation: 312

Training a neural net to predict the winner of a card game

In a made up card game there are 2 players, each of which are dealt 5 cards (standard 52 card deck), after which some arbitrary function decides a winning player. The goal is to predict the outcome of the game, given the 5 cards that each player is holding. The training data could look something like this:

Player A      Player B      Winner

AsKs5d3h2d    JcJd8d7h6s    1
7h5d8s9sTh    2c3c4cAhAs    0
6d6s6h6cQd    AsKsQsJsTs    0

Where the 'Player' columns are 5 card hands, and the 'Winner' column is 1 when player A has won, and 0 when player A has lost.

There should be an indifference towards the order of the hands, such that after training, feeding the network mirrored input data like:

Player A      Player B

2d3d6h7s9s    TsTdJsQc3h

and

Player A      Player B

TsTdJsQc3h    2d3d6h7s9s

will always predict opposite outcomes.

It should also be indifferent to the order of the cards within the hands themselves, such that AsKsQsJsTs is the same as JsTsAsKsQs, which is the same as JsQsTsAsKs etc.

What are some reasonable ways to structure a neural net and its training data to tackle such a problem?

Upvotes: 0

Views: 649

Answers (2)

Frobot
Frobot

Reputation: 1283

You are going to need a network with 104 inputs (players * number of cards) The first 52 inputs correspond to player A, the next 52 correspond to player B. Initialize all inputs to 0, then for each card each player has, set the corresponding input to 1.

For the output layer there are usually two options for binary classification. You can have one output neuron, and if the output of this neuron is greater than a certain threshold, player A wins, else player B wins. Or you can have two output neurons and just look at which one produces the highest output. Both generally work fine.

For training data, instead of something like "AsKs5d3h2d", you will need a one-hot encoding, something like "0001000001000000100100000100000000011001000000001001" (pretend there are 104 numbers, 10 of them are 1's and the rest are 0s) And for output data you just need a 1 or a 0 corresponding to who won (in the case of having one output neuron)

This will make your network invariant to the order of the cards (all possible orders of a given hand will create the same input) And as for swapping player A and B's hands and getting the opposite result, this is something that should come naturally to any well trained network.

Upvotes: 1

saurabh agarwal
saurabh agarwal

Reputation: 2184

First, you should understand the use of Neural Network (NN) before going ahead with this problem. NN tries to find out complex relationship between input and output. (here your input is five cards and output is predicted class).

Here in this question, relationship between input and output can easily be formulated. i.e. you can easily choose some set of rules which declares a final winner.

Still like any other problem, this problem can also be dealt with NN. First you need to prepare your data.

There are total 52 type of inputs possible. So, take 52 column in dataset. Now in these 52 column you can fill three type of categorical data. Either it belongs to 'A' or 'B' or no body. 'C' and output can be the winner .

Now you can train it using NN.

Upvotes: 0

Related Questions