-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit with up to date (stable) verson of RSG Chess.
- Loading branch information
0 parents
commit a4dd918
Showing
16 changed files
with
58,698 additions
and
0 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,5 @@ | ||
node_modules | ||
build | ||
npm-debug.log | ||
.env | ||
.DS_Store |
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,113 @@ | ||
#table{ | ||
background: rgb(209, 139, 71); | ||
border: 1px solid black; | ||
width: 500px; | ||
height: 500px; | ||
float: left; | ||
margin: 10px; | ||
} | ||
|
||
div#app{ | ||
perspective: 1555px; | ||
} | ||
|
||
.rotated { | ||
transform: rotateX(180deg); | ||
} | ||
|
||
.menu-icon { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
|
||
margin: 3px; | ||
font-size: 21px; | ||
cursor: pointer; | ||
} | ||
|
||
div#app > div { | ||
/* transition: transform 1s; | ||
transform: rotateX(15deg) rotateY(-15deg) rotateX(3deg); | ||
transform-origin: 15px 525px 15px; */ | ||
display: inline-block; | ||
} | ||
|
||
div#app > div:hover{ | ||
transform: none; | ||
} | ||
|
||
#table tr:nth-child(odd) td:nth-child(odd){ | ||
background: rgb(255, 206, 158); | ||
} | ||
|
||
#table tr:nth-child(even) td:nth-child(even){ | ||
background: rgb(255, 206, 158); | ||
} | ||
|
||
#table tr:nth-child(even) td:nth-child(odd) { | ||
background: rgb(209, 139, 71); | ||
} | ||
|
||
#table tr:nth-child(odd) td:nth-child(even) { | ||
background: rgb(209, 139, 71); | ||
} | ||
|
||
#table td{ | ||
cursor: pointer; | ||
border: 1px solid gray; | ||
width: 12.5%; | ||
height: 12.5%; | ||
font-size: 35px; | ||
text-align: center; | ||
} | ||
|
||
#app #table .selected { | ||
background: brown; | ||
} | ||
|
||
#app #table .validMoves { | ||
background: red; | ||
} | ||
|
||
#app #table td { | ||
-webkit-transition: background-color 375ms linear; | ||
-moz-transition: background-color 375ms linear; | ||
-o-transition: background-color 375ms linear; | ||
-ms-transition: background-color 375ms linear; | ||
transition: background-color 375ms linear; | ||
} | ||
|
||
#down{ | ||
position: relative; | ||
left: 10px; | ||
top: -17px; | ||
width: 500px; | ||
} | ||
|
||
.down { | ||
width: 12.5%; | ||
font-size: 25px; | ||
text-align: center; | ||
} | ||
|
||
#right { | ||
position: relative; | ||
left: 10px; | ||
top: 10px; | ||
height: 500px; | ||
} | ||
|
||
|
||
.right { | ||
height: 12.5%; | ||
font-size: 25px; | ||
} | ||
|
||
table{ | ||
-webkit-touch-callout: none; | ||
-webkit-user-select: none; | ||
-khtml-user-select: none; | ||
-moz-user-select: none; | ||
-ms-user-select: none; | ||
user-select: none; | ||
} |
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,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>RSG Chess</title> | ||
<meta charset="utf-8"> | ||
<!-- Bootstrap link: --> | ||
<link rel="stylesheet" href="./res/bootstrap.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="text/javascript" src="./js/scripts.min.js" ></script> | ||
<noscript>Your browser does not support JavaScript or it is disabled!</noscript> | ||
<link rel="stylesheet" type="text/css" href="index.css"> | ||
</body> | ||
</html> |
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,16 @@ | ||
const { app, BrowserWindow } = require('electron'); | ||
let mainWindow; | ||
|
||
app.on('ready', () => { | ||
mainWindow = new BrowserWindow({ | ||
height: 800, | ||
width: 800, | ||
icon: './res/icon_192.png' | ||
}); | ||
|
||
mainWindow.loadURL('file://' + __dirname + '/index.html'); | ||
}); | ||
|
||
app.on('browser-window-created',function(e,window) { | ||
window.setMenu(null); | ||
}); |
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,94 @@ | ||
// | ||
// RSG Chess | ||
// Licensed under Apache 2.0 LICENSE | ||
|
||
const Chess_AI = function (game){ | ||
var board = game.board; | ||
// best values /bestMove & bestValue/ | ||
var bestMove = null; | ||
var bestValue = -9999; | ||
for (var i = 0; i < 8; i++) { | ||
for (var j = 0; j < 8; j++) { | ||
board[i][j] && | ||
board[i][j].getValidMoves() | ||
.forEach(function(ev, k){ | ||
// needed variables | ||
var piece = board[i][j] | ||
var from = { x: piece.x, y: piece.y }; | ||
var movePiece = board[ev.y][ev.x] ? { | ||
piece: board[ev.y][ev.x], | ||
from: { x: ev.x, y: ev.y }, | ||
to: null | ||
} : null; | ||
// check for en-passant, and already captured pieces /movePiece/ | ||
if(ev.movePiece) movePiece = ev.movePiece; | ||
if(movePiece) game.simpleMovePiece(movePiece.piece, movePiece.from, movePiece.to); | ||
// simulate the current move from .getValidMoves() array /ev/ | ||
game.simpleMovePiece(piece, from, { x: ev.x, y: ev.y }); | ||
// evulate the board and get the best move /boardValue > bestValue -> bestMove = {.../ | ||
var boardValue = -evaluateBoard(board); | ||
if ( | ||
boardValue > bestValue && | ||
board[ev.y][ev.x].color === 'B' | ||
) { | ||
bestValue = boardValue; | ||
bestMove = { | ||
from: {x: j, y: i}, | ||
to: ev | ||
}; | ||
} | ||
// return the current move /ev/ | ||
game.simpleMovePiece(piece, { x: ev.x, y: ev.y }, from); | ||
if(movePiece) game.simpleMovePiece(movePiece.piece, movePiece.to, movePiece.from); | ||
}) | ||
} | ||
} | ||
// return the best move | ||
return bestMove; | ||
}; | ||
|
||
var evaluateBoard = function (board) { | ||
var totalEvaluation = 0; | ||
for (var i = 0; i < 8; i++) { | ||
for (var j = 0; j < 8; j++) { | ||
// calculate the current evaluation | ||
totalEvaluation = totalEvaluation + getPieceValue(board[i][j]); | ||
} | ||
} | ||
// return the total evaluation | ||
return totalEvaluation; | ||
}; | ||
|
||
var getPieceValue = function (piece) { | ||
if (piece === null) { | ||
return 0; | ||
} | ||
|
||
// get value for every piece on the board | ||
var getAbsoluteValue = function (piece) { | ||
if (piece.type === 'pawn') { | ||
return 10; | ||
} else if (piece.type === 'rook') { | ||
return 50; | ||
} else if (piece.type === 'knight') { | ||
return 30; | ||
} else if (piece.type === 'bishop') { | ||
return 30 ; | ||
} else if (piece.type === 'queen') { | ||
return 90; | ||
} else if (piece.type === 'king') { | ||
return 900; | ||
} | ||
throw "Unknown piece: " + piece.type; | ||
}; | ||
|
||
// calculate the absolute value and return it | ||
var absoluteValue = getAbsoluteValue(piece, piece.color === 'W'); | ||
return piece.color === 'W' ? absoluteValue : -absoluteValue; | ||
}; | ||
|
||
// export the algorithm | ||
export default Chess_AI | ||
|
||
// Written by Radi Cho | ||
// RSG Chess - by RSG Group |
Oops, something went wrong.