@@ -8,28 +8,28 @@ enum HitType { none, hit, partial, miss, removed }
88
99typedef Letter = ({String char, HitType type});
1010
11- const legalWords = < String > [" aback" , " abase" , " abate" , " abbey" , " abbot" ];
11+ const legalWords = < String > [' aback' , ' abase' , ' abate' , ' abbey' , ' abbot' ];
1212
1313/// Legal guesses minus legal wordles
1414const legalGuesses = < String > [
15- " aback" ,
16- " abase" ,
17- " abate" ,
18- " abbey" ,
19- " abbot" ,
20- " abhor" ,
21- " abide" ,
22- " abled" ,
23- " abode" ,
24- " abort" ,
15+ ' aback' ,
16+ ' abase' ,
17+ ' abate' ,
18+ ' abbey' ,
19+ ' abbot' ,
20+ ' abhor' ,
21+ ' abide' ,
22+ ' abled' ,
23+ ' abode' ,
24+ ' abort' ,
2525];
2626
2727/// This class holds game state for a single round of Bulls and Cows,
2828/// and exposes methods that a UI would need to manage the game state.
2929///
30- /// On it's own, this class won't manage a game. For example, it won't
31- /// call [startGame ] on it's own. It assumes that a client will use it's
32- /// methods to progress through a game.
30+ /// On its own, this class won't manage a game.
31+ /// For example, it won't call [resetGame ] on its own.
32+ /// It assumes that a client will use its methods to progress through a game.
3333class Game {
3434 Game ({this .numAllowedGuesses = defaultNumGuesses, this .seed}) {
3535 _wordToGuess = seed == null ? Word .random () : Word .fromSeed (seed! );
@@ -76,7 +76,7 @@ class Game {
7676 bool get didWin {
7777 if (_guesses.first.isEmpty) return false ;
7878
79- for (var letter in previousGuess) {
79+ for (final letter in previousGuess) {
8080 if (letter.type != HitType .hit) return false ;
8181 }
8282
@@ -94,7 +94,7 @@ class Game {
9494 // Doesn't move the game forward, only executes match logic.
9595 Word matchGuessOnly (String guess) {
9696 // The hidden word will be used by subsequent guesses.
97- var hiddenCopy = Word .fromString (_wordToGuess.toString ());
97+ final hiddenCopy = Word .fromString (_wordToGuess.toString ());
9898 return Word .fromString (guess).evaluateGuess (hiddenCopy);
9999 }
100100
@@ -112,16 +112,16 @@ class Word with IterableMixin<Letter> {
112112 }
113113
114114 factory Word .fromString (String guess) {
115- var list = guess.toLowerCase ().split ('' );
116- var letters = list
117- .map ((String char) => (char: char, type: HitType .none))
115+ final list = guess.toLowerCase ().split ('' );
116+ final letters = list
117+ .map ((char) => (char: char, type: HitType .none))
118118 .toList ();
119119 return Word (letters);
120120 }
121121
122122 factory Word .random () {
123- var rand = Random ();
124- var nextWord = legalWords[rand.nextInt (legalWords.length)];
123+ final rand = Random ();
124+ final nextWord = legalWords[rand.nextInt (legalWords.length)];
125125 return Word .fromString (nextWord);
126126 }
127127
@@ -148,7 +148,7 @@ class Word with IterableMixin<Letter> {
148148
149149 @override
150150 String toString () {
151- return _letters.map ((Letter c) => c.char).join ().trim ();
151+ return _letters.map ((c) => c.char).join ().trim ();
152152 }
153153
154154 // Used to play game in the CLI implementation
@@ -168,7 +168,7 @@ extension WordUtils on Word {
168168 }
169169
170170 /// Compares two [Word] objects and returns a new [Word] that
171- /// has the same letters as the [ this] , but each [Letter]
171+ /// has the same letters as this word , but each [Letter]
172172 /// has new a [HitType] of either [HitType.hit] ,
173173 /// [HitType.partial] , or [HitType.miss] .
174174 Word evaluateGuess (Word other) {
@@ -188,12 +188,12 @@ extension WordUtils on Word {
188188 for (var i = 0 ; i < other.length; i++ ) {
189189 // If a letter in the hidden word is already marked as "removed",
190190 // then it's already an exact match, so skip it
191- Letter targetLetter = other[i];
191+ final targetLetter = other[i];
192192 if (targetLetter.type != HitType .none) continue ;
193193
194194 // loop through the guessed word onces for each letter in the hidden word
195195 for (var j = 0 ; j < length; j++ ) {
196- Letter guessedLetter = this [j];
196+ final guessedLetter = this [j];
197197 // skip letters that have already been marked as exact matches
198198 if (guessedLetter.type != HitType .none) continue ;
199199 // If this letter, which must not be in the same position, is the same,
0 commit comments