From 72bcfbadc4c10cbc4ddea2e0119bcc5d98f73a65 Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj <59454579+SashLilac@users.noreply.github.com> Date: Thu, 12 Nov 2020 23:11:11 -0500 Subject: [PATCH] NES Randomizer --- tetris/randomizers/nes.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tetris/randomizers/nes.lua diff --git a/tetris/randomizers/nes.lua b/tetris/randomizers/nes.lua new file mode 100644 index 0000000..c60c590 --- /dev/null +++ b/tetris/randomizers/nes.lua @@ -0,0 +1,19 @@ +local Randomizer = require 'tetris.randomizers.randomizer' + +local NES = Randomizer:extend() + +function NES:initialize() + self.history = 0 + self.shapes = {"I", "J", "L", "O", "S", "T", "Z"} +end + +function NES:generatePiece() + local x = math.random(8) + if x == 8 or x == self.history then + x = math.random(7) + end + self.history = x + return self.shapes[x] +end + +return NES \ No newline at end of file