From: "Timothée Denizou" <denizoutimothee@gmail.com>
To: 56116@debbugs.gnu.org
Subject: bug#56116: Feature: new Tetris randomizer
Date: Mon, 20 Jun 2022 23:41:42 +0200 [thread overview]
Message-ID: <CAHnNzdgk2=9pQwWcuud0EYtzuQXFpaF9BKVDuhfB3yAZ82usMQ@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 516 bytes --]
Getting frustrated about having 4 time in a row the same tetromino ?
Wait no further !
This patch implement the seven bag randomizer, pulling a piece out of
the bag each time and filling the bag when it is empty. This allows for
a more uniform distribution on small samples.
At our school, we have plenty of time at the end of mcqs to play tetris
in emacs and this was something I wanted to change for a bit.
This is also my first contribution ever on an open source project.
The code may not be well formatted.
[-- Attachment #1.2: Type: text/html, Size: 578 bytes --]
[-- Attachment #2: 0001-Feature-new-tetris-randomizer.patch --]
[-- Type: application/octet-stream, Size: 1662 bytes --]
From 3b5b59a654606ce0bd637f62cbf73c3185b79e29 Mon Sep 17 00:00:00 2001
From: Timothee Denizou <timothee.denizou@epita.fr>
Date: Mon, 20 Jun 2022 23:33:32 +0200
Subject: [PATCH] Feature new tetris randomizer
* Added 7 bag randomizer for tetris
A piece is selected from the bag and removed each time we want a piece
When the bag is empty, refill the bag with the seven piece and shuffle it
---
lisp/play/tetris.el | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/lisp/play/tetris.el b/lisp/play/tetris.el
index 8ce2453c75..d8862259ed 100644
--- a/lisp/play/tetris.el
+++ b/lisp/play/tetris.el
@@ -233,6 +233,7 @@ each one of its four blocks.")
(defvar-local tetris-pos-x 0)
(defvar-local tetris-pos-y 0)
(defvar-local tetris-paused nil)
+(defvar-local tetris-bag nil)
;; ;;;;;;;;;;;;; keymaps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -341,10 +342,21 @@ each one of its four blocks.")
(let ((period (tetris-get-tick-period)))
(if period (gamegrid-set-timer period))))
+(defun tetris-shuffle (sequence)
+ (loop for i from (length sequence) downto 2 do
+ (rotatef (elt sequence (random i))
+ (elt sequence (1- i))))
+ sequence)
+
+(defun tetris-seven-bag ()
+ (when (not tetris-bag)
+ (setq tetris-bag (tetris-shuffle (list 0 1 2 3 4 5 6))))
+ (pop tetris-bag))
+
(defun tetris-new-shape ()
(setq tetris-shape tetris-next-shape)
(setq tetris-rot 0)
- (setq tetris-next-shape (random 7))
+ (setq tetris-next-shape (tetris-seven-bag))
(setq tetris-pos-x (/ (- tetris-width (tetris-shape-width)) 2))
(setq tetris-pos-y 0)
(if (tetris-test-shape)
--
2.25.1
next reply other threads:[~2022-06-20 21:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-20 21:41 Timothée Denizou [this message]
2022-06-21 10:59 ` bug#56116: Feature: new Tetris randomizer Lars Ingebrigtsen
2022-06-21 13:08 ` Visuwesh
2022-06-21 17:37 ` Timothée Denizou
2022-06-21 19:51 ` Lars Ingebrigtsen
2022-06-21 20:40 ` Timothée Denizou
2022-06-22 2:25 ` Eli Zaretskii
2022-06-21 11:04 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHnNzdgk2=9pQwWcuud0EYtzuQXFpaF9BKVDuhfB3yAZ82usMQ@mail.gmail.com' \
--to=denizoutimothee@gmail.com \
--cc=56116@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).