From 06d439a4e18e1647c3e4667ea2d9df8a9a1cf8da Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 20 Nov 2023 00:28:10 +0100 Subject: [PATCH 1/6] on commence ici --- src/12_RefactoringGolf/hole1/kata.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/12_RefactoringGolf/hole1/kata.ts b/src/12_RefactoringGolf/hole1/kata.ts index c750e5e..cde22cc 100644 --- a/src/12_RefactoringGolf/hole1/kata.ts +++ b/src/12_RefactoringGolf/hole1/kata.ts @@ -1,5 +1,6 @@ /* eslint-disable */ +// améliore ce code export class Game { private _lastSymbol = ' '; private _toto: Board = new Board(); From c7a6028001da31de041249b39426d374f0490a24 Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 20 Nov 2023 00:44:53 +0100 Subject: [PATCH 2/6] =?UTF-8?q?instruction=20pour=20passer=20=C3=A0=20hole?= =?UTF-8?q?=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{ => 12_RefactoringGolf/hole1}/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{ => 12_RefactoringGolf/hole1}/README.md (100%) diff --git a/src/README.md b/src/12_RefactoringGolf/hole1/README.md similarity index 100% rename from src/README.md rename to src/12_RefactoringGolf/hole1/README.md From 7a5992abe5ac05d09cc29280fe6406a8c1025e6c Mon Sep 17 00:00:00 2001 From: guillaume prof Date: Sun, 15 Sep 2024 23:34:34 +0200 Subject: [PATCH 3/6] clearer instructions for hole1 --- src/12_RefactoringGolf/hole1/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/12_RefactoringGolf/hole1/README.md b/src/12_RefactoringGolf/hole1/README.md index 4cfc9a0..481993a 100644 --- a/src/12_RefactoringGolf/hole1/README.md +++ b/src/12_RefactoringGolf/hole1/README.md @@ -5,7 +5,8 @@ Change the code in hole 1 to be identical to the code in hole 2; implementation ## Refactorings - Tackle code comments, long method and large class - - Extract method + - Extract method where there is a comment + - Extract when, logically, you can divide a method that is too long, into sub methods ## Tips From 6032e8a583528eacb0a24d171d023f1f59e835a6 Mon Sep 17 00:00:00 2001 From: guillaume prof Date: Sun, 15 Sep 2024 23:59:48 +0200 Subject: [PATCH 4/6] Exo1 --- src/12_RefactoringGolf/hole1/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/12_RefactoringGolf/hole1/README.md b/src/12_RefactoringGolf/hole1/README.md index 481993a..2e9c657 100644 --- a/src/12_RefactoringGolf/hole1/README.md +++ b/src/12_RefactoringGolf/hole1/README.md @@ -1,6 +1,5 @@ -# Hole 1 to Hole 2 +# Exo 1 to Exo 2 -Change the code in hole 1 to be identical to the code in hole 2; implementation and tests can change. ## Refactorings From a6600e50b5d633c206d690b6b9ee76f5039f4fc8 Mon Sep 17 00:00:00 2001 From: Yeetnus Date: Mon, 23 Sep 2024 16:25:06 +0200 Subject: [PATCH 5/6] Update kata.ts --- src/12_RefactoringGolf/hole1/kata.ts | 51 ++++++---------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/src/12_RefactoringGolf/hole1/kata.ts b/src/12_RefactoringGolf/hole1/kata.ts index cde22cc..3a8332c 100644 --- a/src/12_RefactoringGolf/hole1/kata.ts +++ b/src/12_RefactoringGolf/hole1/kata.ts @@ -28,48 +28,19 @@ export class Game { } public Winner(): string { - //if the positions in first row are taken - if ( - this._toto.TileAt(0, 0)!.Symbol != ' ' && - this._toto.TileAt(0, 1)!.Symbol != ' ' && - this._toto.TileAt(0, 2)!.Symbol != ' ' - ) { - //if first row is full with same symbol + for (let i=0;i<3;i++) { if ( - this._toto.TileAt(0, 0)!.Symbol == this._toto.TileAt(0, 1)!.Symbol && - this._toto.TileAt(0, 2)!.Symbol == this._toto.TileAt(0, 1)!.Symbol + this._toto.TileAt(i, 0)!.Symbol != ' ' && + this._toto.TileAt(i, 1)!.Symbol != ' ' && + this._toto.TileAt(i, 2)!.Symbol != ' ' ) { - return this._toto.TileAt(0, 0)!.Symbol; - } - } - - //if the positions in first row are taken - if ( - this._toto.TileAt(1, 0)!.Symbol != ' ' && - this._toto.TileAt(1, 1)!.Symbol != ' ' && - this._toto.TileAt(1, 2)!.Symbol != ' ' - ) { - //if middle row is full with same symbol - if ( - this._toto.TileAt(1, 0)!.Symbol == this._toto.TileAt(1, 1)!.Symbol && - this._toto.TileAt(1, 2)!.Symbol == this._toto.TileAt(1, 1)!.Symbol - ) { - return this._toto.TileAt(1, 0)!.Symbol; - } - } - - //if the positions in first row are taken - if ( - this._toto.TileAt(2, 0)!.Symbol != ' ' && - this._toto.TileAt(2, 1)!.Symbol != ' ' && - this._toto.TileAt(2, 2)!.Symbol != ' ' - ) { - //if middle row is full with same symbol - if ( - this._toto.TileAt(2, 0)!.Symbol == this._toto.TileAt(2, 1)!.Symbol && - this._toto.TileAt(2, 2)!.Symbol == this._toto.TileAt(2, 1)!.Symbol - ) { - return this._toto.TileAt(2, 0)!.Symbol; + //if first row is full with same symbol + if ( + this._toto.TileAt(i, 0)!.Symbol == this._toto.TileAt(i, 1)!.Symbol && + this._toto.TileAt(i, 2)!.Symbol == this._toto.TileAt(i, 1)!.Symbol + ) { + return this._toto.TileAt(i, 0)!.Symbol; + } } } From be7b1c05d16aaf9811921ab54af1e7b0ab3ee2f8 Mon Sep 17 00:00:00 2001 From: Yeetnus Date: Mon, 23 Sep 2024 16:35:52 +0200 Subject: [PATCH 6/6] Update 2 --- src/12_RefactoringGolf/hole1/kata.ts | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/12_RefactoringGolf/hole1/kata.ts b/src/12_RefactoringGolf/hole1/kata.ts index 3a8332c..dd72fa3 100644 --- a/src/12_RefactoringGolf/hole1/kata.ts +++ b/src/12_RefactoringGolf/hole1/kata.ts @@ -1,45 +1,38 @@ /* eslint-disable */ -// améliore ce code export class Game { private _lastSymbol = ' '; - private _toto: Board = new Board(); + private _board: Board = new Board(); public Play(symbol: string, x: number, y: number): void { - //if first move if (this._lastSymbol == ' ') { - //if player is X if (symbol == 'O') { throw new Error('Invalid first player'); } } - //if not first move but player repeated else if (symbol == this._lastSymbol) { throw new Error('Invalid next player'); } - //if not first move but play on an already played tile - else if (this._toto.TileAt(x, y).Symbol != ' ') { + else if (this._board.TileAt(x, y).Symbol != ' ') { throw new Error('Invalid position'); } - - // update game state this._lastSymbol = symbol; - this._toto.AddTileAt(symbol, x, y); + this._board.AddTileAt(symbol, x, y); } public Winner(): string { for (let i=0;i<3;i++) { if ( - this._toto.TileAt(i, 0)!.Symbol != ' ' && - this._toto.TileAt(i, 1)!.Symbol != ' ' && - this._toto.TileAt(i, 2)!.Symbol != ' ' + this._board.TileAt(i, 0)!.Symbol != ' ' && + this._board.TileAt(i, 1)!.Symbol != ' ' && + this._board.TileAt(i, 2)!.Symbol != ' ' ) { //if first row is full with same symbol if ( - this._toto.TileAt(i, 0)!.Symbol == this._toto.TileAt(i, 1)!.Symbol && - this._toto.TileAt(i, 2)!.Symbol == this._toto.TileAt(i, 1)!.Symbol + this._board.TileAt(i, 0)!.Symbol == this._board.TileAt(i, 1)!.Symbol && + this._board.TileAt(i, 2)!.Symbol == this._board.TileAt(i, 1)!.Symbol ) { - return this._toto.TileAt(i, 0)!.Symbol; + return this._board.TileAt(i, 0)!.Symbol; } } } @@ -70,8 +63,7 @@ class Board { return this._plays.find((t: Tile) => t.X == x && t.Y == y)!; } - public AddTileAt(symbol: string, x: number, y: number): void { - //@ts-ignore + public AddTileAt(symbol: string, x: number, y: number): void { //@ts-ignore const tile: Tile = { X: x, Y: y, Symbol: symbol }; this._plays.find((t: Tile) => t.X == x && t.Y == y)!.Symbol = symbol;