(this.api, { params })
48 | .pipe(
49 | switchMap(response => {
50 | const bestMove: string = response.bestmove.split(" ")[1];
51 | return of(this.moveFromStockfishString(bestMove));
52 | })
53 | )
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/app/modules/move-list/move-list.component.css:
--------------------------------------------------------------------------------
1 | .move-list {
2 | max-height: 100px;
3 | overflow-y: scroll;
4 | display: flex;
5 | flex-direction: column-reverse;
6 | }
7 |
8 | .move-list::-webkit-scrollbar {
9 | display: none;
10 | }
11 |
12 | .move-list {
13 | -ms-overflow-style: none;
14 | scrollbar-width: none;
15 | }
16 |
17 | .row {
18 | width: 250px;
19 | display: flex;
20 | color: white
21 | }
22 |
23 | .move-number {
24 | width: 50px;
25 | }
26 |
27 | .current-move {
28 | background-color: rgb(0, 143, 168);
29 | }
30 |
31 | .move {
32 | cursor: pointer;
33 | width: 100px;
34 | }
35 |
36 | .move:hover {
37 | background-color: rgb(0, 143, 168);
38 | opacity: 0.7
39 | }
--------------------------------------------------------------------------------
/src/app/modules/move-list/move-list.component.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
15 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
{{moveNumber + 1}}.
26 |
27 |
29 | {{move[0]}}
30 |
31 |
32 |
34 | {{move[1]}}
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/app/modules/move-list/move-list.component.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { Component, EventEmitter, Input, Output } from '@angular/core';
3 | import { MatButtonModule } from '@angular/material/button';
4 | import { MatIconModule } from "@angular/material/icon";
5 | import { MoveList } from 'src/app/chess-logic/models';
6 |
7 | @Component({
8 | selector: 'app-move-list',
9 | templateUrl: './move-list.component.html',
10 | styleUrls: ['./move-list.component.css'],
11 | standalone: true,
12 | imports: [CommonModule, MatButtonModule, MatIconModule]
13 | })
14 | export class MoveListComponent {
15 | @Input({ required: true }) public moveList!: MoveList;
16 | @Input({ required: true }) public gameHistoryPointer: number = 0;
17 | @Input({ required: true }) public gameHistoryLength: number = 1;
18 | @Output() public showPreviousPositionEvent = new EventEmitter();
19 |
20 | public showPreviousPosition(moveIndex: number): void {
21 | this.showPreviousPositionEvent.emit(moveIndex);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/app/modules/nav-menu/nav-menu.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/app/modules/nav-menu/nav-menu.component.css
--------------------------------------------------------------------------------
/src/app/modules/nav-menu/nav-menu.component.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/app/modules/nav-menu/nav-menu.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { MatToolbarModule } from "@angular/material/toolbar";
3 | import { MatButtonModule } from "@angular/material/button"
4 | import { RouterModule } from '@angular/router';
5 | import { MatDialog, MatDialogModule } from "@angular/material/dialog";
6 | import { PlayAgainstComputerDialogComponent } from '../play-against-computer-dialog/play-against-computer-dialog.component';
7 |
8 | @Component({
9 | selector: 'app-nav-menu',
10 | templateUrl: './nav-menu.component.html',
11 | styleUrls: ['./nav-menu.component.css'],
12 | standalone: true,
13 | imports: [MatToolbarModule, MatButtonModule, RouterModule, MatDialogModule]
14 | })
15 | export class NavMenuComponent {
16 |
17 | constructor(private dialog: MatDialog) { }
18 |
19 | public playAgainstComputer(): void {
20 | this.dialog.open(PlayAgainstComputerDialogComponent);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/app/modules/play-against-computer-dialog/play-against-computer-dialog.component.css:
--------------------------------------------------------------------------------
1 | .stockfish-strength-container {
2 | display: flex;
3 | justify-content: space-evenly;
4 | }
5 |
6 | .strength-div {
7 | border: 1px solid white;
8 | cursor: pointer;
9 | width: 40px;
10 | height: 40px;
11 | text-align: center;
12 | font-size: 20px;
13 | line-height: 40px;
14 | }
15 |
16 | .choose-side {
17 | display: flex;
18 | justify-content: space-evenly;
19 | }
20 |
21 | .king-img {
22 | width: 50px;
23 | cursor: pointer;
24 | }
25 |
26 | .selected {
27 | background-color: green;
28 | }
--------------------------------------------------------------------------------
/src/app/modules/play-against-computer-dialog/play-against-computer-dialog.component.html:
--------------------------------------------------------------------------------
1 |
2 | Stockfish Strength
3 |
4 |
5 |
7 | {{level}}
8 |
9 |
10 |
11 |
12 |

13 |

14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/app/modules/play-against-computer-dialog/play-against-computer-dialog.component.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { Component } from '@angular/core';
3 | import { MatButtonModule } from '@angular/material/button';
4 | import { MatDialog, MatDialogModule } from "@angular/material/dialog";
5 | import { StockfishService } from '../computer-mode/stockfish.service';
6 | import { Color } from 'src/app/chess-logic/models';
7 | import { Router } from '@angular/router';
8 |
9 | @Component({
10 | selector: 'app-play-against-computer-dialog',
11 | templateUrl: './play-against-computer-dialog.component.html',
12 | styleUrls: ['./play-against-computer-dialog.component.css'],
13 | standalone: true,
14 | imports: [MatDialogModule, MatButtonModule, CommonModule]
15 | })
16 | export class PlayAgainstComputerDialogComponent {
17 | public stockfishLevels: readonly number[] = [1, 2, 3, 4, 5];
18 | public stockfishLevel: number = 1;
19 |
20 | constructor(
21 | private stockfishService: StockfishService,
22 | private dialog: MatDialog,
23 | private router: Router
24 | ) { }
25 |
26 | public selectStockfishLevel(level: number): void {
27 | this.stockfishLevel = level;
28 | }
29 |
30 | public play(color: "w" | "b"): void {
31 | this.dialog.closeAll();
32 | this.stockfishService.computerConfiguration$.next({
33 | color: color === "w" ? Color.Black : Color.White,
34 | level: this.stockfishLevel
35 | });
36 | this.router.navigate(["against-computer"]);
37 | }
38 |
39 | public closeDialog(): void {
40 | this.router.navigate(["against-friend"]);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/app/routes/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from "@angular/core";
2 | import { ChessBoardComponent } from "../modules/chess-board/chess-board.component";
3 | import { ComputerModeComponent } from "../modules/computer-mode/computer-mode.component";
4 | import { RouterModule, Routes } from "@angular/router";
5 |
6 | const routes: Routes = [
7 | { path: "against-friend", component: ChessBoardComponent, title: "Play against friend" },
8 | { path: "against-computer", component: ComputerModeComponent, title: "Play against computer" }
9 |
10 | ]
11 |
12 | @NgModule({
13 | imports: [RouterModule.forRoot(routes)],
14 | exports: [RouterModule]
15 | })
16 | export class AppRoutingModule { }
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/assets/pieces/black bishop.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/black king.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/black knight.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/black pawn.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/black queen.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/black rook.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/white bishop.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/white king.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/white knight.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/white pawn.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/white queen.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/pieces/white rook.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/sound/capture.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/assets/sound/capture.mp3
--------------------------------------------------------------------------------
/src/assets/sound/castling.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/assets/sound/castling.mp3
--------------------------------------------------------------------------------
/src/assets/sound/check.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/assets/sound/check.mp3
--------------------------------------------------------------------------------
/src/assets/sound/checkmate.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/assets/sound/checkmate.mp3
--------------------------------------------------------------------------------
/src/assets/sound/incorrect-move.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/assets/sound/incorrect-move.mp3
--------------------------------------------------------------------------------
/src/assets/sound/move.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/assets/sound/move.mp3
--------------------------------------------------------------------------------
/src/assets/sound/promote.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/assets/sound/promote.mp3
--------------------------------------------------------------------------------
/src/custom-theme.scss:
--------------------------------------------------------------------------------
1 |
2 | // Custom Theming for Angular Material
3 | // For more information: https://material.angular.io/guide/theming
4 | @use '@angular/material' as mat;
5 | // Plus imports for other components in your app.
6 |
7 | // Include the common styles for Angular Material. We include this here so that you only
8 | // have to load a single css file for Angular Material in your app.
9 | // Be sure that you only ever include this mixin once!
10 | @include mat.core();
11 |
12 | // Define the palettes for your theme using the Material Design palettes available in palette.scss
13 | // (imported above). For each palette, you can optionally specify a default, lighter, and darker
14 | // hue. Available color palettes: https://material.io/design/color/
15 | $chess-game-primary: mat.define-palette(mat.$indigo-palette);
16 | $chess-game-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
17 |
18 | // The warn palette is optional (defaults to red).
19 | $chess-game-warn: mat.define-palette(mat.$red-palette);
20 |
21 | // Create the theme object. A theme consists of configurations for individual
22 | // theming systems such as "color" or "typography".
23 | $chess-game-theme: mat.define-light-theme((
24 | color: (
25 | primary: $chess-game-primary,
26 | accent: $chess-game-accent,
27 | warn: $chess-game-warn,
28 | )
29 | ));
30 |
31 | // Include theme styles for core and each component used in your app.
32 | // Alternatively, you can import and @include the theme mixins for each component
33 | // that you are using.
34 | @include mat.all-component-themes($chess-game-theme);
35 |
36 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awsomeCStutorials/chess-game/87420327bd8eea68a6d462eac60372daee263441/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ChessGame
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2 |
3 | import { AppModule } from './app/app.module';
4 |
5 |
6 | platformBrowserDynamic().bootstrapModule(AppModule)
7 | .catch(err => console.error(err));
8 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 | * {
3 | margin: 0;
4 | padding: 0;
5 | box-sizing: border-box;
6 | }
7 |
8 | html,
9 | body {
10 | height: 100%;
11 | background-color: black;
12 | }
13 |
14 | body {
15 | margin: 0;
16 | font-family: Roboto, "Helvetica Neue", sans-serif;
17 | }
18 | html, body { height: 100%; }
19 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
20 |
--------------------------------------------------------------------------------
/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/app",
6 | "types": []
7 | },
8 | "files": [
9 | "src/main.ts"
10 | ],
11 | "include": [
12 | "src/**/*.d.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "compileOnSave": false,
4 | "compilerOptions": {
5 | "baseUrl": "./",
6 | "outDir": "./dist/out-tsc",
7 | "forceConsistentCasingInFileNames": true,
8 | "strict": true,
9 | "noImplicitOverride": true,
10 | "noPropertyAccessFromIndexSignature": true,
11 | "noImplicitReturns": true,
12 | "noFallthroughCasesInSwitch": true,
13 | "sourceMap": true,
14 | "declaration": false,
15 | "downlevelIteration": true,
16 | "experimentalDecorators": true,
17 | "moduleResolution": "node",
18 | "importHelpers": true,
19 | "target": "ES2022",
20 | "module": "ES2022",
21 | "useDefineForClassFields": false,
22 | "lib": [
23 | "ES2022",
24 | "dom"
25 | ]
26 | },
27 | "angularCompilerOptions": {
28 | "enableI18nLegacyMessageIdFormat": false,
29 | "strictInjectionParameters": true,
30 | "strictInputAccessModifiers": true,
31 | "strictTemplates": true
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/spec",
6 | "types": [
7 | "jasmine"
8 | ]
9 | },
10 | "include": [
11 | "src/**/*.spec.ts",
12 | "src/**/*.d.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------