File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,12 @@ const VIDEO_WIDTH = document.getElementById('output').clientWidth;
1212const VIDEO_HEIGHT = document . getElementById ( 'output' ) . clientHeight ;
1313const mobile = false ;
1414const predictionThreshold = 0.999 ;
15+ const shootThreshold = 5 ;
1516let youScore = 0 ;
1617let comScore = 0 ;
1718let youSymbol = undefined ;
1819let comSymbol = undefined ;
20+ let shootCount = 0 ;
1921
2022function 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 }
You can’t perform that action at this time.
0 commit comments