josefzila / bash2048 Goto Github PK
View Code? Open in Web Editor NEWBash implementation of 2048 game
License: The Unlicense
Bash implementation of 2048 game
License: The Unlicense
the script closes instantly when the game is lost
It's a bit slow for larger grids (20x20).
It could be improved by avoiding $(command), which creates a subshell. Most importantly within tight loops.
Example of performance improvement:
182 function apply_push {
183 printf "\n\ninput: $1 key\n" >&3
184 declare -i i=0
185 while [ $i -le $index_max ]; do
186 declare -i j=0
187 while [ $j -le $index_max ]; do
188 flag_skip=0
189 let increment_max=index_max-j
190 declare -i k=1
191 while [ $k -le $increment_max ]; do
192 let flag_skip && break
193 push_pieces $i $j $k $1 $2
194 k=$k+1
195 done~
196 j=$j+1
197 done
198 i=$i+1
199 done
Please, I want to upload it to Fedora Repository, Could you please a Open SOurce license..
https://fedoraproject.org/wiki/Licensing:Main?rd=Licensing
Also, the tiles don't move in the way I think they should from pressing the arrow keys. Try it.
(Great job though!)
Bash 2048 v1.1 (https://github.com/mydzor/bash2048) pieces=14 target=1048576 score=211020
/------+------+------+------+------\
| | 2 | | | |
|------+------+------+------+------|
| 2 | 64 | | | |
|------+------+------+------+------|
| 16 | 4 | 4 | | |
|------+------+------+------+------|
| 64 | 16 | 8 | 2 | |
|------+------+------+------+------|
| 16384 | 4 | 64 | 8 | |
\------+------+------+------+------/
If you allow large targets, you should adapt the cell width
Do you remember the old(er) games that displayed how long you played the game in the end screen?
Would be nice if bash2048 would show the play time at the end screen (Game Over and Win).
diff --git a/bash2048.sh b/bash2048.sh
index bba4d73..ae7c507 100755
--- a/bash2048.sh
+++ b/bash2048.sh
@@ -209,6 +209,13 @@ function key_react {
D) apply_push left;;
esac
}
+ } || {
+ case $REPLY in
+ k) apply_push up;;
+ j) apply_push down;;
+ l) apply_push right;;
+ h) apply_push left;;
+ esac
}
}
Hi,
I thought it'd be cool if the user can see/save his highscores. What do you think of this feature?
I could eventually open a PR if you feel it is interesting.
Regards
Attached is a patch that adds a score to the game.
It also replaces all occureces of "echo" with printf for compatibility and adds a trap handler for SIGINT wich calls "end_game()"
As it is now, it is hard to distinguish an 8
from a 4
or a 16
from a 64
since they're all of the same colour.
Very cool command-line version!
The board appears like this:
`
/------|------|------|------\
------ | ------ | ------ | ------ |
2 | |||
------ | ------ | ------ | ------ |
4 | |||
------ | ------ | ------ | ------/ |
` |
In Ubuntu, when the target is reached or there are no moves, the terminal just exits. There's not time to look at the text echoed!
Is this free software?
It doesn't work using
curl -s https://raw.githubusercontent.com/mydzor/bash2048/master/bash2048.sh | bash
or
curl -s https://raw.githubusercontent.com/mydzor/bash2048/master/bash2048.sh | sponge | bash
Might have to do with combining them, moving up and to the right.
Otherwise, neat.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.