Skip to content

Commit 237e059

Browse files
committed
enforce shoot
1 parent e4ad8f6 commit 237e059

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

html/rps-tf/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ const VIDEO_WIDTH = document.getElementById('output').clientWidth;
1212
const VIDEO_HEIGHT = document.getElementById('output').clientHeight;
1313
const mobile = false;
1414
const predictionThreshold = 0.999;
15+
const shootThreshold = 5;
1516
let youScore = 0;
1617
let comScore = 0;
1718
let youSymbol = undefined;
1819
let comSymbol = undefined;
20+
let shootCount = 0;
1921

2022
function drawKeypoints(ctx, keypoints) {
2123
function drawPoint(ctx, y, x, r) {
@@ -142,7 +144,11 @@ const landmarksRealTime = async (video) => {
142144
const d = captureData(annots);
143145
const r = predict(d);
144146
if (r.prob >= predictionThreshold) {
145-
if (r.symbol === 'shoot' && youSymbol) {
147+
if (r.symbol === 'shoot') {
148+
shootCount++;
149+
}
150+
151+
if (r.symbol === 'shoot' && shootCount >= shootThreshold && youSymbol) {
146152
comSymbol = getComputerSymbol();
147153
const winner = getWinner(youSymbol, comSymbol);
148154
if (winner === 'user') {
@@ -156,6 +162,7 @@ const landmarksRealTime = async (video) => {
156162
updateLastSymbols();
157163
youSymbol = undefined;
158164
comSymbol = undefined;
165+
shootCount = 0;
159166
} else if (r.symbol === 'rock' || r.symbol === 'paper' || r.symbol === 'scissor') {
160167
youSymbol = r.symbol;
161168
}

0 commit comments

Comments
 (0)