Greed: Difference between revisions

m
syntax highlighting fixup automation
m (added whitespace, equated "erased" and "eaten".)
m (syntax highlighting fixup automation)
 
(One intermediate revision by one other user not shown)
Line 22:
Windows console version.
[[File:newGreedCpp.png|200px|thumb|right]]
<langsyntaxhighlight lang="cpp">
#include <windows.h>
#include <iostream>
Line 143:
greed g; g.play(); return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|Factor}}==
This uses Factor's own user interface vocabularies. Use hjkl-bnyu (vi-keys) to move.
<langsyntaxhighlight lang="factor">USING: accessors arrays colors combinators
combinators.short-circuit fry grouping io io.styles kernel lexer
literals make math math.matrices math.parser math.vectors random
Line 321:
] with-ui ;
 
MAIN: greed-window</langsyntaxhighlight>
{{out}}
[https://i.imgur.com/3IEo8cC.png Screenshot of the game after a loss]
Line 333:
 
Note that this version uses the Z key (rather than the Y key) to move diagonally downwards to the left. A leave key, L, has also been added in case one wants to end the game prematurely.
<langsyntaxhighlight lang="go">package main
 
import (
Line 557:
}
}
}</langsyntaxhighlight>
 
=={{header|Kotlin}}==
Line 563:
{{works with|Windows 10}}
Note that this version uses the Z key (rather than the Y key) to move diagonally downwards to the left.
<langsyntaxhighlight lang="scala">// Kotlin Native v0.5
 
import kotlinx.cinterop.*
Line 760:
srand(time(null).toInt())
Greed().play()
}</langsyntaxhighlight>
 
=={{header|Java}}==
Line 770:
=={{header|Julia}}==
GUI version. Click a square adjacent to the "@" symbol to move.
<langsyntaxhighlight lang="julia">using Gtk
 
struct BState
Line 871:
# greedapp(22, 79) # This would be per task, though a smaller game board is nicer
greedapp(12, 29)
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
Line 883:
And we also added a score field to the BState object in order to restore the correct score when undoing a move.
 
<langsyntaxhighlight Nimlang="nim">import random, strutils
import gintro/[gobject, glib, gtk, gio]
 
Line 1,031:
let app = newApplication(Application, "Rosetta.greed")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 1,100:
if ($c eq 'c') { execute( 1, 0) if $Y < $h } # South
if ($c eq 'v') { execute( 1, 1) if $X < $w and $Y < $h } # South-East
}</langsyntaxhighlight>
 
=={{header|Phix}}==
{{trans|C++}}
<langsyntaxhighlight Phixlang="phix">constant W = 79, H = 22, NCOUNT = W*H
 
sequence board
Line 1,209:
end while
end procedure
play()</langsyntaxhighlight>
 
=={{header|PicoLisp}}==
Computer play by selecting random road. [https://asciinema.org/a/369181 Demo] is here.
<syntaxhighlight lang="picolisp">
<lang PicoLisp>
(load "@lib/simul.l")
(seed (in "/dev/urandom" (rd 8)))
Line 1,311:
(=: A 0) ) )
(display) ) )
(bye)</langsyntaxhighlight>
 
=={{header|Raku}}==
{{trans|Phix}}
<syntaxhighlight lang="raku" perl6line># 20200913 added Raku programming solution
 
srand 123456;
Line 1,367:
when 'v' { execute( 1, 1) if X < w and Y < h } # South-East
}
}</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 1,375:
 
Pointers (above and to the right of) the grid are included to help identify where the current location is.
<langsyntaxhighlight lang="rexx">/*REXX program lets a user play the game of GREED (by Matthew Day) from the console. */
parse arg sw sd @ b ?r . /*obtain optional argumenst from the CL*/
if sw=='' | sw=="," then sw= 79 /*cols specified? Then use the default*/
Line 1,451:
if r==!r then _= _ '◄' /*indicate row of current position. */
if tell then say _ /*display a row of grid to screen. */
end /*r*/; say; return # /*SHOW also counts # of blanks (score).*/</langsyntaxhighlight>
A note on the OUTPUT sections: &nbsp; each (cleared) screen displayed is shown below as a separate OUTPUT section.
 
Line 1,501:
</pre>
 
 
=={{header|Wren}}==
 
See [[Greed/Wren]].
 
=={{header|Z80 Assembly}}==
10,333

edits