added train buttons
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
</section>
|
</section>
|
||||||
<section w-full>
|
<section w-full>
|
||||||
<p><button nbButton outline status="danger" (click)="resetGame()">Neues Spiel!<br /></button><br /></p>
|
<p><button nbButton outline status="danger" (click)="resetGame()">Neues Spiel!<br /></button><br /></p>
|
||||||
|
<p><button nbButton outline status="danger" (click)="trainUp('X')" *ngIf="winner">Train like X!<br /></button><br /></p>
|
||||||
|
<p><button nbButton outline status="danger" (click)="trainUp('O')" *ngIf="winner">Train like O!<br /></button><br /></p>
|
||||||
<h1>current player: {{ player }}</h1>
|
<h1>current player: {{ player }}</h1>
|
||||||
<h2 *ngIf="winner">Gewinner: {{ winner }}<br /></h2><br />
|
<h2 *ngIf="winner">Gewinner: {{ winner }}<br /></h2><br />
|
||||||
</section>
|
</section>
|
||||||
@@ -10,3 +12,4 @@
|
|||||||
<app-square class="square-container h-48" *ngFor="let val of fields; let i=index" [value]="val"
|
<app-square class="square-container h-48" *ngFor="let val of fields; let i=index" [value]="val"
|
||||||
(click)="playerPress(i)"></app-square>
|
(click)="playerPress(i)"></app-square>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,29 @@ export class BoardComponent implements OnInit {
|
|||||||
this.resetGame();
|
this.resetGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trainUp(playerLearn) {
|
||||||
|
console.log('Train Called - to be more like ', playerLearn);
|
||||||
|
|
||||||
|
const AllMoves = this.history.map((board) => {
|
||||||
|
return board.map((v) => {
|
||||||
|
if (v === playerLearn) {
|
||||||
|
return 1;
|
||||||
|
} else if (v === null) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
console.log(AllMoves);
|
||||||
|
// let ai: AiService;
|
||||||
|
// let games = [];
|
||||||
|
// games.push(AllMoves);
|
||||||
|
// ai = new AiService();
|
||||||
|
// ai.trainOnGames(games, (data)=>{console.log(data)});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
resetGame() {
|
resetGame() {
|
||||||
this.winner = null;
|
this.winner = null;
|
||||||
this.draw = false;
|
this.draw = false;
|
||||||
@@ -34,7 +57,7 @@ export class BoardComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playerPress(i: number) {
|
playerPress(i: number) {
|
||||||
if(this.winner != null) {
|
if (this.winner != null) {
|
||||||
this.resetGame();
|
this.resetGame();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user