MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / gameToFeaturesAndLabel

Function gameToFeaturesAndLabel

data-generator/index.js:56–66  ·  view source on GitHub ↗

* Takes the state of one complete game and returns features suitable for * training. Returns an object containing features = player1's hand represented * using oneHot encoding, and label = whether player 1 won. * @param {*} gameState

(gameState)

Source from the content-addressed store, hash-verified

54 * @param {*} gameState
55 */
56function gameToFeaturesAndLabel(gameState) {
57 return tf.tidy(() => {
58 const player1Hand = tf.tensor1d(gameState.player1Hand, 'int32');
59 const handOneHot = tf.oneHot(
60 tf.sub(player1Hand, tf.scalar(1, 'int32')),
61 game.GAME_STATE.max_card_value);
62 const features = tf.sum(handOneHot, 0);
63 const label = tf.tensor1d([gameState.player1Win]);
64 return {xs: features, ys: label};
65 });
66}
67
68/**
69 * Collects one random play of the game. Processes the sample to generate

Callers 2

simulateGameHandlerFunction · 0.85
predictHandlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected