Giter Site home page Giter Site logo

contentsviewer / shtris Goto Github PK

View Code? Open in Web Editor NEW
48.0 4.0 7.0 344 KB

The pure shell script (sh) that implements the Tetris game following the Tetris Guideline (2009).

Home Page: https://contentsviewer.work/Master/ShellScript/Apps/Tetris/Tetris

License: MIT License

Shell 100.00%
shell tetris sh bash

shtris's Introduction

shtris's People

Contributors

contentsviewer avatar eggplants avatar ko1nksm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

shtris's Issues

Pause / Resume

I think it would be useful to be able to pause and resume the game.

We need to hide the playfield while posing. The Tetris guideline says the following.

  • Esc and F1 are to pause.
  • Game must count down from 3 after you press start, and after you resume a paused game.

I create an Issue as you might want to implement this. I will contact you before I start the implementation.

High load on ksh93

I noticed that the load was very high on ksh93. This is probably a bug related to local variables (typeset) in ksh93. This is not reproduced by ksh93u+m and ksh2020.

Note: ksh2020 is the latest version on macOS, but it is a discarded version due to compatibility issues. The official latest version is ksh93u+, and the unofficial bug-fixed version is ksh93u+m.

This can be reproduced in the following way. If you remove typeset, it will work fine.

diff --git a/tetris b/tetris
index c08a360..ee04710 100755
--- a/tetris
+++ b/tetris
@@ -530,7 +530,7 @@ if (PATH=/dev/null; f() { local v; }; f) 2>/dev/null; then
 else
   localvar() {
     set -- "$1" "$*"
-    eval "function $1 { typeset${2#"$1"}; _$1 \"\$@\"; }"
+    eval "function $1 { _$1 \"\$@\"; }"
   }
 fi

Use typeset to reproduce it. (You may need to play with it for a while.)

@@ -1587,10 +1587,10 @@ _redraw_playfield() {
 #   4 - rotation
 #   5 - cell content
 #   6 - mask with playfield
-localvar draw_piece posx posy type rotation content x y mask
-_draw_piece() {
+#localvar draw_piece posx posy type rotation content x y mask
+function draw_piece {
   # at first, we should save arguments.
-  posx="$1"; posy="$2"; type="$3"; rotation="$4"; content="$5"; mask="${6:-false}"
+  typeset posx="$1"; posy="$2"; type="$3"; rotation="$4"; content="$5"; mask="${6:-false}"

   # set minos coordinates.
   eval set -- \$piece_"$type"_minos_"$rotation"

I have an idea to implement a stack to store variables as a way to achieve local variables instead of typeset. But in my opinion, it's overdoing.

I think it is better to stop using local and typeset and use global variables carefully. The current code works with very little modification. I am going to create a PR for the proposed changes.

Allow replay without exiting the program after a game over

I think it would be useful to be able to replay without exiting the program after a game over. This allows you to skip the display time of copyright.

I create an Issue as you might want to implement this. I will contact you before I start the implementation.

Over level 15

Previously, the level raised up to 16 when I accomplish the goal lines in level 15.
But now:

image

Add "bash" to the topics

Currently there are only shell, tetris and sh in the topics, how about adding bash? sh-tetris already works with bash. This will make it easier to find this project.

スクリーンショット 2022-01-15 9 40 27

40 line Time attack

I would like to play 40 line time attack (splint mode) and measure LPM (erase lines per minute).

  • 40 line mode (called sprint or 40 lines)

Optimizing the overhead of the sleep command

As with any other command, there is an overhead in executing the sleep command.

# FALL_SPEED_LEVEL_15=0.007
$ time sh -c 'i=0; while [ $i -lt 1000 ]; do i=$((i+1)); sleep 0.007 > /dev/null; done'

real	0m11.345s
user	0m0.911s
sys	0m1.748s

I would like to eliminate this. I suspect that measuring the execution time of the sleep command will improve this issue. I don't know if this will work, but I am going to give it a try.

A new way for shtris user

Hello, friends.

I recently includes shtris as a package in x-cmd. Now, users can simply type "x shtris" and x-cmd will automatically download and execute. https://www.x-cmd.com/pkg/shtris

Installing x-cmd is extremely easy. Just run eval "$(curl https://get.x-cmd.com)" and the process should be quick since x-cmd only uses shawk (shell/awk) and curl.

For more information on installation, please visit https://www.x-cmd.com/.

Maybe you can consider using x-cmd to start shtris.

Thank you to bring this game to terminal using shell.

Standard color theme does not match with light theme terminal

standard color theme does not match with light theme terminal.

image

This issue may be fixed if standard color theme respects terminal color theme.
However, orange color still need to be specified, so it will be conflicted the others, as you know🤔

`--no-beep` is not working

Even if I give script --no-beep option, terbell still rings.
no_beep flag seems to be unused. Is not handler implemented?

v2.2.0 Release

@ko1nksm @eggplants

Hello!
Thank you for your kindness and contributions!

As you know, there are many changes and improvements from v2.1.0.

I'd like to freeze the features and release the next version (v2.2.0). (But still going to fix bugs and merge small changes.)

I'll plan to release between 2021-12-30 ~ 2022-01-03.

Unexpected error "Illegal instruction: 4" occurs in /bin/sh on macOS Big Sur

I'm currently having trouble with this error. If this error occurs within tetris, the lockdown_timer will stop functioning. It may take some time for the error to occur.

I think this is probably an issue with macOS (Big Sur?). And I'm guessing it's an issue with /bin/sh (bash 3.2.57 with apple patches). So this is a report to share information. Do you have any information on this?

This is a small code that can be reproduced.

#!/bin/sh

set -eu

timer() {
  trap ':' USR1
  while kill -0 "$1"; do
    sleep 0.0001 &
    wait ||:
  done
  echo "timer end" >&2
}

reader() {
  while kill -0 "$1"; do
    sleep 0.1 # smaller values should be more likely to occur
    echo "reader 0"
  done
  echo "reader end" >&2
}

controller() {
  timer_pid="$1"
  echo "start [timer:$timer_pid]"
  while IFS= read -r line; do
    kill -USR1 "$timer_pid"
  done
}

timer "$$" & timer_pid=$!
reader "$$" | controller "$timer_pid" # line 31
$ sh tetris
start [timer:26583]
tetris: line 26: kill: (26583) - No such process
tetris: line 31: 26583 Illegal instruction: 4  timer "$$"
The issue does not occur in the original bash 3.2.57.
$ docker run -it fidian/multishell
$ cat <<'HERE'>tetris
#!/bin/sh

set -eu

timer() {
  trap ':' USR1
  while kill -0 "$1"; do
    sleep 0.0001 &
    wait ||:
  done
  echo "timer end" >&2
}

reader() {
  while kill -0 "$1"; do
    sleep 0.1
    echo "reader 0"
  done
  echo "reader end" >&2
}

controller() {
  timer_pid="$1"
  echo "start [timer:$timer_pid]"
  while IFS= read -r line; do
    kill -USR1 "$timer_pid"
  done
}

timer "$$" & timer_pid=$!
reader "$$" | controller "$timer_pid" # line 31
HERE
$ bash-3.2.57 tetris

This Issue is only for sharing information and you are free to close it. If I can find a workaround, I'll suggesting it.

Copyright

https://tetris.fandom.com/wiki/Tetris_Guideline

  • Game must have this notice when the game starts (XXXX is the year the game was created):
Tetris © 1985~XXXX Tetris Holding.
Tetris logos, Tetris theme song and Tetriminos are > trademarks of Tetris Holding.
The Tetris trade dress is owned by Tetris Holding.
Licensed to The Tetris Company.
Tetris Game Design by Alexey Pajitnov.
Tetris Logo Design by Roger Dean.
All Rights Reserved.

Unexpected display of "Mini T-Spin"

I may be mistaken, but I think it sometimes shows up as "Mini T-Spin" when I am not doing Mini T-Spin. I am not sure how to reproduce this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.