Skip to content
Snippets Groups Projects
Commit 4ad2d4c5 authored by KaspHell's avatar KaspHell
Browse files

fixes for successful build

parent 46f0bc24
No related branches found
No related tags found
No related merge requests found
Pipeline #25067 passed
......@@ -15,9 +15,9 @@ class App extends Component {
super(props);
this.state = {
match: {
result: "default",
userChoice: "default",
aiChoice: "default",
result: "",
userChoice: "",
aiChoice: "",
},
matchId: 1
}
......@@ -40,14 +40,10 @@ class App extends Component {
handlePlay(userChoice) {
const plays = ["Rock", "Paper", "Scissors"]
const aiChoice = plays[Math.floor(Math.random() * plays.length)]
console.log("...............")
console.log(userChoice)
console.log(aiChoice)
switch (userChoice + aiChoice) {
case "RockRock":
case "ScissorsScissors":
case "PaperPaper":
console.log("draw")
this.updateMatch({
result: "Draw",
userChoice: userChoice,
......@@ -58,7 +54,6 @@ class App extends Component {
case "RockScissors":
case "ScissorsPaper":
case "PaperRock":
console.log("win")
this.updateMatch({
result: "Win",
userChoice: userChoice,
......@@ -69,13 +64,18 @@ class App extends Component {
case "ScissorsRock":
case "PaperScissors":
case "RockPaper":
console.log("lose")
this.updateMatch({
result: "Lose",
userChoice: userChoice,
aiChoice: aiChoice
})
break;
default:
this.updateMatch({
result: "",
userChoice: "",
aiChoice: ""
})
}
}
......
import React, { useState, useEffect } from 'react'
import React, { useState, useEffect, useCallback } from 'react'
import * as tmImage from '@teachablemachine/image'
import loadVideo from '../utilities/camera'
......@@ -38,13 +38,13 @@ Loads image recognition model from cloud
* Loop to use image recognition continually
* @param {[videofeed]} image [description]
*/
async function predictVideo(image) {
const predictVideo = useCallback(async (image) => {
if (model) {
const predict = await model.predict(image, 4)
setPrediction(predict)
predictVideo(userWebCam)
}
}
}, [userWebCam, model])
/**
* Copy of App.js gameplay logics. Takes user input, generates ai input and calculates
......@@ -92,6 +92,12 @@ Loads image recognition model from cloud
aiChoice: aiChoice
})
break;
default:
this.updateMatch({
result: "",
userChoice: "",
aiChoice: ""
})
}
}
......@@ -140,7 +146,7 @@ Loads image recognition model from cloud
if (userWebCam) {
predictVideo(userWebCam)
}
}, [userWebCam, model])
}, [predictVideo, userWebCam, model])
return (
<div class="parent flexbox-item-2">
......
......@@ -19,7 +19,7 @@ class Guide extends Component {
<div class="infos">
<ul>
<li class="info">Created by Kasperi Hellstedt</li>
<li class="info">Source code on <a href="">GitHub</a></li>
<li class="info">Source code on <a href="https://gitlab.utu.fi/kshell/rps_react">GitLab</a></li>
<li class="info">
Powered by <a href="https://teachablemachine.withgoogle.com/">Google's Teachable Machine</a>
, <a href="https://www.tensorflow.org/js/?hl=fi/">Tensorflow.js</a> and <a href="https://reactjs.org/">ReactJS</a>
......
......@@ -9,7 +9,7 @@ class Header extends Component {
return (
<div class="flexbox-item-1">
<h1>Real Rocks Papers and Scissors </h1>
<h3>RPS -gmae with image recognition AI</h3>
<h3>RPS -game with image recognition AI</h3>
</div>
)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment