-
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.
- Loading branch information
1 parent
92ab65d
commit b27076e
Showing
32 changed files
with
477 additions
and
142 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
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 |
---|---|---|
@@ -1,5 +1 @@ | ||
include: package:very_good_analysis/analysis_options.yaml | ||
|
||
linter: | ||
rules: | ||
public_member_api_docs: false | ||
include: package:very_good_analysis/analysis_options.yaml |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
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
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
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 @@ | ||
/// Represents the state/status of a given game. | ||
enum GameStatus { | ||
/// {@template game_status} | ||
/// Game is in a | ||
/// {@endtemplate} | ||
/// win state. | ||
win, | ||
|
||
/// {@macro game_status} | ||
/// loss state. | ||
loss, | ||
|
||
/// {@macro game_status} | ||
/// can continue state. | ||
cont, | ||
} |
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,19 @@ | ||
import 'package:clordle/clordle.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
/// {@template letter} | ||
/// The game's representation of a letter. | ||
/// {@endtemplate} | ||
class Letter extends Equatable { | ||
/// {@macro letter} | ||
const Letter(this.status, this.character); | ||
|
||
/// The current state of this letter. | ||
final LetterStatus status; | ||
|
||
/// This letter's character string. | ||
final String character; | ||
|
||
@override | ||
List<Object> get props => [status, character]; | ||
} |
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,20 @@ | ||
/// The state or status of any given letter in the game. | ||
enum LetterStatus { | ||
/// {@template letter_status} | ||
/// Represents a letter that | ||
/// {@endtemplate} | ||
/// is matching. | ||
hit, | ||
|
||
/// {@macro letter_status} | ||
/// does not match. | ||
miss, | ||
|
||
/// {@macro letter_status} | ||
/// is in the same word, but the incorrect location. | ||
close, | ||
|
||
/// {@macro letter_status} | ||
/// has not yet been check/played. | ||
unmatched, | ||
} |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
export 'game_state.dart'; | ||
export 'game_status.dart'; | ||
export 'letter.dart'; | ||
export 'letter_status.dart'; | ||
export 'word.dart'; |
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,39 @@ | ||
import 'package:clordle/clordle.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
/// {@template word} | ||
/// The game's representation of a word. | ||
/// {@endtemplate} | ||
class Word extends Equatable { | ||
/// {@macro word} | ||
const Word(this.letters); | ||
|
||
/// Generate a word from a guess. | ||
factory Word.fromGuess(String guess, String wordle) => | ||
Word(_letterMapper(guess, wordle).toList()); | ||
|
||
/// The letters that represent this word. | ||
final List<Letter> letters; | ||
|
||
/// Whether each letter in this words is a matching letter. | ||
bool get isMatch => letters.every((l) => l.status == LetterStatus.hit); | ||
|
||
static Iterable<Letter> _letterMapper(String guess, String wordle) sync* { | ||
final guessLetters = guess.split(''); | ||
final wordleLetters = wordle.split(''); | ||
|
||
for (var i = 0; i < guessLetters.length; i++) { | ||
final gLetter = guessLetters[i]; | ||
if (gLetter == wordleLetters[i]) { | ||
yield Letter(LetterStatus.hit, gLetter); | ||
} else if (wordle.contains(gLetter)) { | ||
yield Letter(LetterStatus.close, gLetter); | ||
} else { | ||
yield Letter(LetterStatus.miss, gLetter); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
List<Object> get props => [letters]; | ||
} |
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,9 @@ | ||
import 'package:clordle/clordle.dart'; | ||
|
||
/// Evaluates the given [game] and determines if the game has not ended. | ||
bool gameShouldContinue(GameState game, String Function(String) guesser) { | ||
return game.guess( | ||
guesser('GUESS:').toUpperCase().padRight(5).substring(0, 5), | ||
) == | ||
GameStatus.cont; | ||
} |
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
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 |
---|---|---|
@@ -1,8 +1,3 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:clordle/clordle.dart'; | ||
|
||
String getWord() { | ||
final index = Random().nextInt(words.length); | ||
return words[index]; | ||
} | ||
/// Select the word from [words] using the selector. | ||
String getWord(List<String> words, int Function(int) selector) => | ||
words[selector(words.length)]; |
Oops, something went wrong.