package game

import (
	"math/rand"
)

type ShapeQueue struct {
	shapes []ShapeType
}

func NewShapeQueue() *ShapeQueue {
	sq := &ShapeQueue{
		shapes: []ShapeType{},
	}
	sq.Generate()
	return sq
}

func (sq *ShapeQueue) Generate() {
	types := []ShapeType{
		SHAPE_I,
		SHAPE_J,
		SHAPE_L,
		SHAPE_O,
		SHAPE_S,
		SHAPE_T,
		SHAPE_Z,
	}
	rand.Shuffle(len(types), func(i int, j int) {
		types[i], types[j] = types[j], types[i]
	})

	sq.shapes = append(sq.shapes, types...)
}

func (sq *ShapeQueue) Next() Shape {
	if len(sq.shapes) < 1 {
		sq.Generate()
	}
	t := sq.shapes[0]
	sq.shapes = sq.shapes[1:]
	return NewShape(t)
}
