Compare commits
No commits in common. "3c19338971827a45b7a47d256ce307d4abd4ef72" and "c843003b66725030e05ee975e5c47679f3d433d6" have entirely different histories.
3c19338971
...
c843003b66
7 changed files with 41 additions and 48 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
/bin
|
|
BIN
bin/bordle
Executable file
BIN
bin/bordle
Executable file
Binary file not shown.
|
@ -1,33 +1,32 @@
|
||||||
|
|
||||||
class Bordle
|
class Bordle
|
||||||
class Dictionary
|
class Dictionary
|
||||||
DICTIONARY_PATH = Path.new("/usr/share/dict/")
|
DICTIONARY_FILE = "/usr/share/dict/french"
|
||||||
|
|
||||||
property length : UInt8
|
property length : UInt8
|
||||||
property data : Array(String)
|
property data : Array(String)
|
||||||
property language : String = "french"
|
|
||||||
|
|
||||||
def initialize(length : UInt8)
|
def initialize(length : UInt8)
|
||||||
@length = length
|
@length = length
|
||||||
@data = [] of String
|
@data = [] of String
|
||||||
load_data
|
load_data
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_data
|
def load_data
|
||||||
dictionary_file = DICTIONARY_PATH / @language
|
|
||||||
# use french dictionary from wfrench package
|
# use french dictionary from wfrench package
|
||||||
if !File.exists? dictionary_file
|
if ! File.exists? DICTIONARY_FILE
|
||||||
STDERR.puts "ERROR: dictionary file missing! (#{dictionary_file})"
|
STDERR.puts "ERROR: dictionary file missing! (#{DICTIONARY_FILE})"
|
||||||
STDERR.puts " Please install then w#{@language} package on your system"
|
STDERR.puts " Please install then wfrench package on your system"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
lines = File.read_lines(dictionary_file)
|
lines = File.read_lines(DICTIONARY_FILE)
|
||||||
@data =
|
@data =
|
||||||
lines
|
lines
|
||||||
.select {|word| word.size == @length }
|
.select {|word| word.size == @length }
|
||||||
.map { |word| word.tr( TR_DIACRITICS, TR_ASCII ) }
|
.map { |word| word.tr( TR_DIACRITICS, TR_ASCII ) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def includes?(word)
|
def includes?(word)
|
||||||
@data.includes? word
|
@data.includes? word
|
||||||
end
|
end
|
||||||
|
|
18
src/game.cr
18
src/game.cr
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
require "colorize"
|
require "colorize"
|
||||||
|
|
||||||
require "./types"
|
require "./types"
|
||||||
|
@ -36,28 +37,14 @@ class Bordle
|
||||||
word = "" if word.nil?
|
word = "" if word.nil?
|
||||||
word.tr(TR_DIACRITICS, TR_ASCII).downcase
|
word.tr(TR_DIACRITICS, TR_ASCII).downcase
|
||||||
|
|
||||||
error = [] of String
|
|
||||||
error << "language" if !@dict.includes? word
|
|
||||||
error << "length" if word.size != @length
|
|
||||||
break if word.size == @length && @dict.includes? word
|
break if word.size == @length && @dict.includes? word
|
||||||
printf("\x1B[A\x1B[2K")
|
printf("\x1B[A\x1B[2K")
|
||||||
puts "-- #{word} : invalid #{error.join(" and ")} --"
|
|
||||||
end
|
end
|
||||||
word
|
word
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
puts "-- BORDLE (#{@target.inspect}) --".colorize.fore(:blue)
|
printf " .....\n"
|
||||||
puts <<-MARK
|
|
||||||
1. You win when you find the secret word.
|
|
||||||
2. You have 5 attempts; you lose if you use them all.
|
|
||||||
3. The secret word is in #{@dict.language} and 5 characters long.
|
|
||||||
4. Language and length mistakes are not counted as attemps.
|
|
||||||
5. Diacritics (accents, etc.) are removed.
|
|
||||||
6. Use CTRL-C to exit.
|
|
||||||
MARK
|
|
||||||
puts ""
|
|
||||||
puts " ....."
|
|
||||||
try = 0
|
try = 0
|
||||||
while true
|
while true
|
||||||
try += 1
|
try += 1
|
||||||
|
@ -78,3 +65,4 @@ class Bordle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
10
src/main.cr
10
src/main.cr
|
@ -1,12 +1,14 @@
|
||||||
|
|
||||||
require "option_parser"
|
require "option_parser"
|
||||||
|
|
||||||
require "./game"
|
require "./game"
|
||||||
|
|
||||||
class Bordle
|
class Bordle
|
||||||
class BordleCli
|
class BordleCli
|
||||||
|
|
||||||
property options : String?
|
property options : String?
|
||||||
|
|
||||||
def initialize
|
def initialize()
|
||||||
@options = nil
|
@options = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -15,7 +17,7 @@ class Bordle
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: add --length LEN option (length of words)
|
# FIXME: add --length LEN option (length of words)
|
||||||
# FIXME: add --language LANG option (choose dictionnary)
|
# FIXME: add --lang LANG option (choose dictionnary)
|
||||||
# FIXME: add --tries TRIES option (how many tries are allowed)
|
# FIXME: add --tries TRIES option (how many tries are allowed)
|
||||||
# FIXME: add --with-letters (show used/unused letters)
|
# FIXME: add --with-letters (show used/unused letters)
|
||||||
def self.run(args)
|
def self.run(args)
|
||||||
|
@ -24,9 +26,11 @@ class Bordle
|
||||||
app.options = options
|
app.options = options
|
||||||
|
|
||||||
game = Game.new
|
game = Game.new
|
||||||
game.run
|
game.run()
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Bordle::BordleCli.run(ARGV)
|
Bordle::BordleCli.run(ARGV)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
class Bordle
|
class Bordle
|
||||||
class TargetWord
|
class TargetWord
|
||||||
def initialize(@target_word : String)
|
def initialize(@target_word : String)
|
||||||
|
@ -7,7 +8,7 @@ class Bordle
|
||||||
@target_word == word
|
@target_word == word
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_h
|
def to_h()
|
||||||
hash = Hash(Char, Array(Int32)).new
|
hash = Hash(Char, Array(Int32)).new
|
||||||
@target_word.each_char_with_index do |char, index|
|
@target_word.each_char_with_index do |char, index|
|
||||||
hash[char] = [] of Int32 unless hash.has_key? char
|
hash[char] = [] of Int32 unless hash.has_key? char
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
|
||||||
class Bordle
|
class Bordle
|
||||||
TR_DIACRITICS = "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšȘșſŢţŤťŦŧȚțÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž"
|
TR_DIACRITICS = "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšȘșſŢţŤťŦŧȚțÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž"
|
||||||
TR_ASCII = "AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSsSssTtTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz"
|
TR_ASCII = "AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSsSssTtTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz"
|
||||||
|
|
||||||
|
|
||||||
enum Score
|
enum Score
|
||||||
RightPlace = 0
|
RightPlace = 0
|
||||||
WrongPlace = 1
|
WrongPlace = 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue