Open goblinrieur opened 1 month ago
hope this helps you
require random.fs
vocabulary mines
also mines definitions
10 constant bomb
: n #0. next-arg >number 2drop drop ;
n constant width
n constant height
width height * chars constant length
create field length chars allot
field length erase
: index swap width * + ;
: tile chars field + ;
: tile@ tile c@ ;
: tile! swap tile c! ;
length random tile constant shown
: "bomb" $1f4a3 xemit ;
: "empty" $2b1c xemit ;
: "number" $30 + xemit $fe0f xemit $20e3 xemit space ;
: "tile" ?dup if "number" else "empty" then ;
: "bomb?" dup bomb = if drop "bomb" else "tile" then ;
: "tile#" dup c@ "bomb?" char+ ;
: "tile." dup shown = if "tile#" else "tile#" then ;
: row width 0 do "tile." space loop cr ;
: show field height 0 do space row loop drop ;
: #bombs length dup 4 rshift swap 3 rshift random + ;
: bombs #bombs for length random bomb tile! next ;
create x+
-1 , 0 , 1 , -1 , 1 , -1 , 0 , 1 ,
: +x cells x+ + @ + ;
create y+
-1 , -1 , -1 , 0 , 0 , 1 , 1 , 1 ,
: +y cells y+ + @ + ;
variable count
: valid? 0 width within if 0 height within else drop 0 then ;
: bomb? index tile@ bomb = ;
: ?count bomb? if 1 count +! then ;
: +count over over valid? if ?count else 2drop then ;
: set index count @ tile! ;
: number 0 count ! 8 0 do over i +y over i +x +count loop set ;
: numbers height 0 do width 0 do j i j i bomb? 0= if number then loop loop ;
: main cr bombs numbers show cr ;
\ page \ optionnal
main 0 (bye)
forgot the bash runner :
#! /usr/bin/env bash
runner=$(which gforth-fast)
if [[ ${runner} != *"gforth-fast"* ]] ; then
echo "Gforth interpreter not found"
exit 1
fi
trap '' SIGINT
$runner ./mines.fs $1 $2
trap SIGINT
tput cnorm
exit $?
thank you. where did you learn bash? i poorly understood most of your script but found it useful anyway. among those, i don't understand the trap command. so what if the forth says something to the system? it's fine.
the forth code is flawed, but it's not the tabulation or redefinition X)
how did you find my project?
сб, 3 авг. 2024 г. в 08:51, goblinrieur @.***>:
forgot the bash runner :
! /usr/bin/env bash
runner=$(which gforth-fast)
if [[ ${runner} != "gforth-fast" ]] ; then echo "Gforth interpreter not found" exit 1 fi trap '' SIGINT $runner ./mines.fs $1 $2 trap SIGINT tput cnorm exit $?
— Reply to this email directly, view it on GitHub https://github.com/origedit/mines/issues/1#issuecomment-2266644032, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOGOAMVXISA76POVFKK6FUDZPSK23AVCNFSM6AAAAABL44BI6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRWGY2DIMBTGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Hello, here is the bash runner I use for my forth projects you can inspire your self from this adjusting to your needs :)