Skip to content

Commit

Permalink
Added chessAI and resolved all issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AyishikD committed Jun 17, 2023
1 parent 114474f commit 773b14c
Show file tree
Hide file tree
Showing 42 changed files with 15,064 additions and 20,194 deletions.
8 changes: 8 additions & 0 deletions babel.config.js
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
],
};

12,794 changes: 15 additions & 12,779 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/preset-env": "^7.22.5",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@babel/standalone": "^7.22.5",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/chess.js": "^0.13.4",
"@types/redux": "^3.6.0",
"axios": "^1.4.0",
"bootstrap": "^5.3.0",
"chess.js": "^1.0.0-beta.6",
"chessboardjsx": "^2.4.7",
"framer-motion": "^10.12.16",
"gsap": "^3.12.1",
"i": "^0.3.7",
"react": "^18.2.0",
"react-compound-timer": "^1.2.0",
"react-confetti": "^6.1.0",
"react-dom": "^18.2.0",
"react-icons": "^4.9.0",
Expand Down Expand Up @@ -50,8 +58,10 @@
]
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"html-loader": "^4.2.0",
"resolve-url-loader": "^5.0.0",
"sass": "^1.63.3"
"sass": "^1.63.3",
"typescript": "^5.1.3"
}
}
1 change: 1 addition & 0 deletions src/Games/ChessAI/.eslintcache
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",[]]
7 changes: 2 additions & 5 deletions src/Games/ChessAI/README.md
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
89 changes: 89 additions & 0 deletions src/Games/ChessAI/appiz.js
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;
39 changes: 22 additions & 17 deletions src/Games/ChessAI/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
{
"name": "chess-ai",
"name": "chess-game",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"typescript": "~3.7.2"
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"chess.js": "^0.11.0",
"chessboardjsx": "^2.4.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"typescript": "^4.0.3",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
Expand All @@ -39,6 +43,7 @@
]
},
"devDependencies": {
"gh-pages": "^2.2.0"
}
"@types/chess.js": "^0.10.1"
},
"homepage": "https://varunpvp.github.io/random-chess"
}
Binary file modified src/Games/ChessAI/public/favicon.ico
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/BBishop.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/BKing.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/BKnight.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/BPawn.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/BQueen.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/BRook.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/Queen.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/WBishop.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/WKing.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/WKnight.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/WPawn.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/WQueen.png
Binary file not shown.
Binary file removed src/Games/ChessAI/public/gfx/WRook.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Games/ChessAI/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Random Chess</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
34 changes: 5 additions & 29 deletions src/Games/ChessAI/src/App.css
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%;
}
13 changes: 0 additions & 13 deletions src/Games/ChessAI/src/App.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/Games/ChessAI/src/App.test.tsx
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();
});
Loading

0 comments on commit 773b14c

Please sign in to comment.