unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56116: Feature: new Tetris randomizer
@ 2022-06-20 21:41 Timothée Denizou
  2022-06-21 10:59 ` Lars Ingebrigtsen
  2022-06-21 11:04 ` Eli Zaretskii
  0 siblings, 2 replies; 8+ messages in thread
From: Timothée Denizou @ 2022-06-20 21:41 UTC (permalink / raw)
  To: 56116


[-- 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#56116: Feature: new Tetris randomizer
  2022-06-20 21:41 bug#56116: Feature: new Tetris randomizer Timothée Denizou
@ 2022-06-21 10:59 ` Lars Ingebrigtsen
  2022-06-21 13:08   ` Visuwesh
  2022-06-21 11:04 ` Eli Zaretskii
  1 sibling, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-21 10:59 UTC (permalink / raw)
  To: Timothée Denizou; +Cc: 56116

Timothée Denizou <denizoutimothee@gmail.com> writes:

> 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.

Thanks for the contribution.  But this would change gameplay
considerably -- in Tetris, you can get the same shape four times in a
row, while with your change, that's no longer possible.  I.e., it makes
the game less random, so I'm not sure that would be a welcome change.
(And you can predict which ones you'll be getting at the end of each
seven piece cycle by counting a bit.)

It might make sense to add it as an option, though.  Any Tetris players
here with an opinion?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#56116: Feature: new Tetris randomizer
  2022-06-20 21:41 bug#56116: Feature: new Tetris randomizer Timothée Denizou
  2022-06-21 10:59 ` Lars Ingebrigtsen
@ 2022-06-21 11:04 ` Eli Zaretskii
  1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2022-06-21 11:04 UTC (permalink / raw)
  To: Timothée Denizou; +Cc: 56116

> From: Timothée Denizou <denizoutimothee@gmail.com>
> Date: Mon, 20 Jun 2022 23:41:42 +0200
> 
> 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.

Thanks.  A few comments below.

> 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.

This patch is small enough for us to accept it unconditionally, but if
you plan on contributing in future, we'd need you to sign copyright
assignment papers.  If you're okay with that, I will send you the form
to fill and the instructions to go with it.

> 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

Please use our conventions of formatting commit log messages like
ChangeLog entries.  You can find the details in the file CONTRIBUTE.

The description enough is good, but maybe a better place for it would
be a comment near the relevant code.

> +(defun tetris-shuffle (sequence)
> +  (loop for i from (length sequence) downto 2 do
> +    (rotatef (elt sequence (random i))
> +             (elt sequence (1- i))))
> +  sequence)

I guess you meant cl-rotatef?  rotatef is unbound in "emacs -Q", even
after I load tetris.el.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#56116: Feature: new Tetris randomizer
  2022-06-21 10:59 ` Lars Ingebrigtsen
@ 2022-06-21 13:08   ` Visuwesh
  2022-06-21 17:37     ` Timothée Denizou
  0 siblings, 1 reply; 8+ messages in thread
From: Visuwesh @ 2022-06-21 13:08 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 56116, Timothée Denizou

[செவ்வாய் ஜூன் 21, 2022] Lars Ingebrigtsen wrote:

> Timothée Denizou <denizoutimothee@gmail.com> writes:
>
>> 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.
>
> Thanks for the contribution.  But this would change gameplay
> considerably -- in Tetris, you can get the same shape four times in a
> row, while with your change, that's no longer possible.  I.e., it makes
> the game less random, so I'm not sure that would be a welcome change.
> (And you can predict which ones you'll be getting at the end of each
> seven piece cycle by counting a bit.)
>
> It might make sense to add it as an option, though.  Any Tetris players
> here with an opinion?

Full disclaimer: I am only an occasional Tetris player, and I haven't
played other Tetris implementations (nor the original), I quickly tried
out one game with and without the patch, I think `random' makes the game
more challenging to play.  Part of the fun when playing this game,
although very frustrating, is figuring out how to manage the playground
when Emacs throws you the same block five times (especially the Zs!!)
but the uniform distribution kills this aspect.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#56116: Feature: new Tetris randomizer
  2022-06-21 13:08   ` Visuwesh
@ 2022-06-21 17:37     ` Timothée Denizou
  2022-06-21 19:51       ` Lars Ingebrigtsen
  2022-06-22  2:25       ` Eli Zaretskii
  0 siblings, 2 replies; 8+ messages in thread
From: Timothée Denizou @ 2022-06-21 17:37 UTC (permalink / raw)
  To: Visuwesh; +Cc: Lars Ingebrigtsen, 56116

[-- Attachment #1: Type: text/plain, Size: 2083 bytes --]

Le mar. 21 juin 2022 à 13:04, Eli Zaretskii <eliz@gnu.org> a écrit :
> This patch is small enough for us to accept it unconditionally, but if
> you plan on contributing in future, we'd need you to sign copyright
> assignment papers.  If you're okay with that, I will send you the form
> to fill and the instructions to go with it.

I'm ok with that, do I need to provide an address ? One of my friend
worked on XBoard and signed his papers at our School located
14-16 Rue Voltaire, 94270 Le Kremlin-Bicetre. If you need to send any,
this is the address.

> I guess you meant cl-rotatef?  rotatef is unbound in "emacs -Q", even
> after I load tetris.el.

Yes cl-rotatef is the one.

> Please use our conventions of formatting commit log messages like
> ChangeLog entries.  You can find the details in the file CONTRIBUTE.

Thanks for the guiding. Should I remake the patch in order to comply ?

Le mar. 21 juin 2022 à 12:59, Lars Ingebrigtsen <larsi@gnus.org> a écrit :
> It might make sense to add it as an option, though.  Any Tetris players
> here with an opinion?

That is a good idea

Le mar. 21 juin 2022 à 15:08, Visuwesh <visuweshm@gmail.com> a écrit :
 > I think `random' makes the game
> more challenging to play.  Part of the fun when playing this game,
> although very frustrating, is figuring out how to manage the playground
> when Emacs throws you the same block five times (especially the Zs!!)
> but the uniform distribution kills this aspect.

Random definitely makes the game harder but it also makes it more
frustrating.
Modern tetris implementations (Tetris 99 and Tetris Effect) both
use the 7-bag randomizer, as well as a 'hold' cell and a preview of
respectively 6 and 4 pieces.
While this definitely reduce difficulty in a sens, it definitely adds
fluidity
and speed, as well as a more competitive aspect to it. Scores can get
much higher as well.

I propose this change mostly in this purpose (fun, speed and
competition) but I understand the more 'retro' style like the original
game or the NES version.

[-- Attachment #2: Type: text/html, Size: 3293 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#56116: Feature: new Tetris randomizer
  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
  1 sibling, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-21 19:51 UTC (permalink / raw)
  To: Timothée Denizou; +Cc: 56116, Visuwesh

Timothée Denizou <denizoutimothee@gmail.com> writes:

> Modern tetris implementations (Tetris 99 and Tetris Effect) both
> use the 7-bag randomizer, as well as a 'hold' cell and a preview of
> respectively 6 and 4 pieces.
> While this definitely reduce difficulty in a sens, it definitely adds fluidity
> and speed, as well as a more competitive aspect to it. Scores can get
> much higher as well.

Makes sense, but I can see people wanting both versions.  So I've pushed
your patch (with some changes) to Emacs 29, guarded by a new user
option, tetris-allow-repetitions.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#56116: Feature: new Tetris randomizer
  2022-06-21 19:51       ` Lars Ingebrigtsen
@ 2022-06-21 20:40         ` Timothée Denizou
  0 siblings, 0 replies; 8+ messages in thread
From: Timothée Denizou @ 2022-06-21 20:40 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 56116, Visuwesh

[-- Attachment #1: Type: text/plain, Size: 832 bytes --]

Thank you very much !

Le mar. 21 juin 2022 à 21:51, Lars Ingebrigtsen <larsi@gnus.org> a écrit :

> Timothée Denizou <denizoutimothee@gmail.com> writes:
>
> > Modern tetris implementations (Tetris 99 and Tetris Effect) both
> > use the 7-bag randomizer, as well as a 'hold' cell and a preview of
> > respectively 6 and 4 pieces.
> > While this definitely reduce difficulty in a sens, it definitely adds
> fluidity
> > and speed, as well as a more competitive aspect to it. Scores can get
> > much higher as well.
>
> Makes sense, but I can see people wanting both versions.  So I've pushed
> your patch (with some changes) to Emacs 29, guarded by a new user
> option, tetris-allow-repetitions.
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no
>

[-- Attachment #2: Type: text/html, Size: 1312 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#56116: Feature: new Tetris randomizer
  2022-06-21 17:37     ` Timothée Denizou
  2022-06-21 19:51       ` Lars Ingebrigtsen
@ 2022-06-22  2:25       ` Eli Zaretskii
  1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2022-06-22  2:25 UTC (permalink / raw)
  To: Timothée Denizou; +Cc: larsi, 56116, visuweshm

> Cc: Lars Ingebrigtsen <larsi@gnus.org>, 56116@debbugs.gnu.org
> From: Timothée Denizou <denizoutimothee@gmail.com>
> Date: Tue, 21 Jun 2022 19:37:42 +0200
> 
> Le mar. 21 juin 2022 à 13:04, Eli Zaretskii <eliz@gnu.org> a écrit :
> > This patch is small enough for us to accept it unconditionally, but if
> > you plan on contributing in future, we'd need you to sign copyright
> > assignment papers.  If you're okay with that, I will send you the form
> > to fill and the instructions to go with it.
> 
> I'm ok with that, do I need to provide an address ? One of my friend
> worked on XBoard and signed his papers at our School located
> 14-16 Rue Voltaire, 94270 Le Kremlin-Bicetre. If you need to send any,
> this is the address.

Thanks, form sent off-list.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-22  2:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-20 21:41 bug#56116: Feature: new Tetris randomizer Timothée Denizou
2022-06-21 10:59 ` 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

Code repositories for project(s) associated with this 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).