-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added chessAI and resolved all issues
- Loading branch information
Showing
42 changed files
with
15,064 additions
and
20,194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
presets: [ | ||
"@babel/preset-env", // Transpile modern JavaScript syntax to older versions | ||
"@babel/preset-react", // Transpile JSX syntax | ||
"@babel/preset-typescript", // Transpile TypeScript syntax | ||
], | ||
}; | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"/Users/varun/Desktop/chess-game/src/App.tsx":"1"},{"size":1126,"mtime":1607674683322,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"2goybq","/Users/varun/Desktop/chess-game/src/App.tsx",[]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
# Chess AI Engine | ||
# Random Chess | ||
|
||
A Chess AI Engine created in TypeScript with React.js as the front-end. | ||
Implemented using the MiniMax Algorithm with Alpha-Beta pruning for improved efficiency. | ||
|
||
Can be tried out [here](https://hjjinx.github.io/chess-ai/) | ||
Play random chess with computer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { useState } from "react"; | ||
import "./src/App.css"; | ||
import Timer from "react-compound-timer"; | ||
import Chessboard from "chessboardjsx"; | ||
import { Chess } from "chess.js"; | ||
|
||
const paddingStyle = { | ||
padding: 5 | ||
}; | ||
|
||
const marginStyle = { | ||
margin: 5 | ||
}; | ||
|
||
const App = () => { | ||
const [chess] = useState(new Chess()); | ||
|
||
const [fen, setFen] = useState(chess.fen()); | ||
|
||
const handleMove = (move) => { | ||
if (chess.move(move)) { | ||
setTimeout(() => { | ||
const moves = chess.moves(); | ||
if (moves.length > 0) { | ||
const computerMove = | ||
moves[Math.floor(Math.random() * moves.length)]; | ||
chess.move(computerMove); | ||
setFen(chess.fen()); | ||
} | ||
}, 300); | ||
setFen(chess.fen()); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="flex-center"> | ||
<h1>Random Chess Game</h1> | ||
<Chessboard | ||
width={400} | ||
position={fen} | ||
onDrop={(move) => | ||
handleMove({ | ||
from: move.sourceSquare, | ||
to: move.targetSquare, | ||
promotion: "q" | ||
}) | ||
} | ||
/> | ||
<Timer initialTime={0} startImmediately={false}> | ||
{({ start, resume, pause, stop, reset, timerState }) => ( | ||
<> | ||
<div> | ||
<span style={paddingStyle}> | ||
<Timer.Minutes /> minutes | ||
</span> | ||
<span style={paddingStyle}> | ||
<Timer.Seconds /> seconds | ||
</span> | ||
<span style={paddingStyle}> | ||
<Timer.Milliseconds /> milliseconds | ||
</span> | ||
</div> | ||
<div style={paddingStyle}>{timerState}</div> | ||
<br /> | ||
<div> | ||
<button style={marginStyle} onClick={start}> | ||
Start | ||
</button> | ||
<button style={marginStyle} onClick={pause}> | ||
Pause | ||
</button> | ||
<button style={marginStyle} onClick={resume}> | ||
Resume | ||
</button> | ||
<button style={marginStyle} onClick={stop}> | ||
Stop | ||
</button> | ||
<button style={marginStyle} onClick={reset}> | ||
Reset | ||
</button> | ||
</div> | ||
</> | ||
)} | ||
</Timer> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,7 @@ | ||
.app { | ||
text-align: center; | ||
} | ||
|
||
.app_board { | ||
width: 800px; | ||
display: grid; | ||
grid-template-rows: repeat(8, 100px); | ||
border: 1px solid black; | ||
} | ||
|
||
.row { | ||
.flex-center { | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
.box { | ||
display: "flex"; | ||
width: 100px; | ||
height: 100px; | ||
border: 1px solid black; | ||
box-sizing: border-box; | ||
background-color: rgb(254, 206, 161); | ||
} | ||
|
||
.row:nth-child(2n + 1) .box:nth-child(2n) { | ||
background-color: rgb(208, 139, 76); | ||
} | ||
.row:nth-child(2n) .box:nth-child(2n + 1) { | ||
background-color: rgb(208, 139, 76); | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import App from './App'; | ||
import { render, screen } from '@testing-library/react'; | ||
import App from '../appiz'; | ||
|
||
test('renders learn react link', () => { | ||
const { getByText } = render(<App />); | ||
const linkElement = getByText(/learn react/i); | ||
render(<App />); | ||
const linkElement = screen.getByText(/learn react/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
}); |
Oops, something went wrong.