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

Function compareHands

data-generator/game.js:117–134  ·  view source on GitHub ↗
(hand1, hand2)

Source from the content-addressed store, hash-verified

115 * @returns {number} 1 or 0 indicating Player 1's win or loss, respectively.
116 */
117export function compareHands(hand1, hand2) {
118 const handScore1 = handScoringHelper(hand1);
119 const handScore2 = handScoringHelper(hand2);
120 // In descending order of group size, decide if one hand is better.
121 for (let group = GAME_STATE.num_cards_per_hand - 1; group >= 0; group--) {
122 if (handScore1[group] > handScore2[group]) {
123 return 1;
124 }
125 if (handScore1[group] < handScore2[group]) {
126 return 0;
127 }
128 }
129 // Break a tie by flipping a fair coin.
130 if (Math.random() > 0.5) {
131 return 1;
132 }
133 return 0;
134}
135
136/**
137 * Returns an object representing one complete play of the game.

Callers 1

generateOnePlayFunction · 0.85

Calls 1

handScoringHelperFunction · 0.85

Tested by

no test coverage detected