Permalink
Browse files

add bag rng (and remove stats)

  • Loading branch information...
1 parent 950f8b1 commit cea5c6e86fe738ec76112a1d639249322afdbc5a @nooodl committed Jun 22, 2013
Showing with 28 additions and 28 deletions.
  1. +0 −26 src/draw/draw.c
  2. +27 −2 src/game/tetris.c
  3. +1 −0 src/game/tetris.h
View
@@ -250,30 +250,6 @@ static void print_top_scores()
refreshwin(WIN_TOP_SCORES);
}
-static void print_tetr_stats()
-{
- const char letters[8] = "IJLOSTZ";
- int sum = 0;
- int i;
- if (term_width < 45)
- return;
- setwcurs(WIN_TETROM_STATS, 1, 0);
- for (i = 0; i < 7; i++) {
- setblockcolor(tetrom_colors[i]);
- putch(block_chars[0]);
- putch(letters[i]);
- putch(block_chars[1]);
- setattr_normal();
- printint(" %03d", tetr_stats[i]);
- newln(1);
- sum += tetr_stats[i];
- }
- printstr(" -----");
- newln(0);
- printint("Sum %04d", sum);
- refreshwin(WIN_TETROM_STATS);
-}
-
void drawgamescreen_1p()
{
drawboard(1);
@@ -284,7 +260,6 @@ void drawgamescreen_1p()
redrawboard(&player1, 19);
drawpanel_1p();
print_top_scores();
- print_tetr_stats();
refreshwin(WIN_PANEL);
}
@@ -436,7 +411,6 @@ void upd_stat(const struct player *p, int levelup)
else
printstat_1p();
print_top_scores();
- print_tetr_stats();
}
refreshwin(WIN_PANEL);
}
View
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "tetris.h"
@@ -753,11 +754,35 @@ void setupplayer(struct player *p)
while (p->level < p->startlevel)
levelup(p);
p->lines = (game->mode & MODE_BTYPE) ? p->lineslimit : 0;
+ memset(p->bag, 0, 7);
+}
+
+static int random_piece() {
+ int i, n = 0;
+ int choices[7];
+
+ /* Count unused pieces */
+ for (i = 0; i < 7; i++) {
+ if (!player1.bag[i]) {
+ choices[n++] = i;
+ }
+ }
+
+ /* If none left, fill the bag and take any piece */
+ if (n == 0) {
+ memset(player1.bag, 0, 7);
+ i = randnum(7);
+ } else {
+ i = choices[randnum(n)];
+ }
+
+ player1.bag[i] = 1;
+ return i;
}
static int nextpiece(struct tetr *next)
{
- int i = randnum(7);
+ int i = random_piece();
player1.piece = *next;
gettetrom(next, i);
tetr_stats[i]++;
@@ -768,7 +793,7 @@ static int nextpiece(struct tetr *next)
int startgame_1p()
{
struct tetr next;
- int i = randnum(7);
+ int i = random_piece();
int t;
drawgamescreen_1p();
gettetrom(&next, i);
View
@@ -61,6 +61,7 @@ struct player {
short lines;
short mvleft_tm;
short mvright_tm;
+ char bag[7];
};
/* game modes */

0 comments on commit cea5c6e

Please sign in to comment.