Wordle comparison: Difference between revisions

Content added Content deleted
(→‎{{header|FutureBasic}}: Replaced with more compact revised code)
Line 357: Line 357:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
This compact FutureBasic function fills an array of color objects which can be applied directly to whatever output is chosen, as demonstrated in the 'show' function. It is useful for games up to 15 chars wide, and is case sensitive as specified.
This compact function returns a byte array (as a pstring) with 2, 1, 0, for matched, mismatched, unmatched. It is useful for games up to 15 chars wide, and is case sensitive as specified.
<syntaxhighlight lang="futurebasic">
<syntaxhighlight lang="futurebasic">
short x = 80, y = 20


clear local fn colorString( w1 as str15, w2 as str15 ) as str15
short x, y = -29
str255 n : str15 c : c[0] = w2[0] : short r

for r = 1 to w1[0]
clear local fn wordleCompare( wordle as str15, guess as str15, cArray(15) as colorRef )
if w2[r] = w1[r] then c[r] = 2 else n[w1[r]]++
/* Returns colors in passed array "cArray()". */
byte count(255)
short r
for r = 1 to wordle[0]
if guess[r] == wordle[r] then cArray(r) = fn colorGreen : continue
count(wordle[r])++ : cArray(r) = fn colorGray
next
next
for r = 1 to w2[0]
if c[r] == 0 then if n[w2[r]] then n[w2[r]]-- : c[r] = 1
for r = 1 to guess[0]
if cArray(r) == fn colorGreen then continue
if count(guess[r]) then count(guess[r])-- : cArray(r) = fn colorYellow
next
next
end fn = c
</syntaxhighlight>
end fn
This function uses the array to display output mimicking the appearance of WORDLE.

<syntaxhighlight lang="futurebasic">
local fn show( wordle as str15, guess as str15 )
mda(0) = {fn ColorDarkGray,fn ColorWithRGB(.7,.6,.3,1),fn ColorWithRGB(.3,.6,.3,1)}
colorref color(15)
void local fn wordleCompare( wordle as str15, guess as str15 )
short r
x = 130 : y += 32
str15 color : short r
fn wordleCompare( wordle, guess, color(0) ) //get color array
color = fn colorString( wordle, guess )
text @"menlo", 27, fn colorgray : print %( 20, y ) wordle
text @"menlo bold", 14, fn colorLightGray
text ,,fn colorBlack
print %( 20, y ) wordle : text ,,fn colorWhite
for r = 1 to guess[0]
for r = 1 to guess[0]
rect fill ( x, y + 8, 28, 28 ), color(r) //apply color from array to square
rect fill ( x, y, 24, 24 ), mda_object( color[r] )
print %( x + 5, y ) chr$(guess[r]); : x += 29
print %( x + 7.5, y + 1 ) chr$( guess[r] ); : x += 28
next
next
x = 80 : y += 28
end fn
end fn


window 1, @"Wordle Compare in FutureBasic",(0,0,310,350)
window 1, @"FB Wordle Compare", ( 0, 0, 265, 290 )
WindowSetBackgroundColor( 1, fn Colorblack )
fn show( "ALLOW", "LOLLY" )
fn show( "CHANT", "LATTE" )
fn wordleCompare( "ALLOW", "LOLLY" )
fn show( "ROBIN", "SONIC" )
fn wordleCompare( "CHANT", "LATTE" )
fn show( "ROBIN", "ROBIN" )
fn wordleCompare( "ROBIN", "SONIC" )
fn show( "ROBIN", "ALERT" )
fn wordleCompare( "PROUD", "LEAST" )
fn show( "BULLY", "LOLLY" )
fn wordleCompare( "STEAL", "LEAST" )
fn show( "STEAL", "LEAST" )
fn wordleCompare( "LEAST", "LEAST" )
fn show( "CHOIR", "LEAST" )
fn wordleCompare( "FULLY", "LABEL" )
fn show( "SILLY", "LABEL" )
fn wordleCompare( "We're", "She's" )
fn show( "Swiss", "sissy" )
fn wordleCompare("LONGER", "STRING")


handleevents
handleevents
</syntaxhighlight>
</syntaxhighlight>
{{out}}
{{out}}
[[File:FutureBasic Output for Wordle Comparison.png]]
[[File:Wordle Comparison in FutureBasic.png]]


=={{header|Go}}==
=={{header|Go}}==