package smallrocket

import "fmt"

type SequentialQueue struct {
	Items  []any // 队列元素
	Length int32 // 队列元素个数
	Cap    int32 // 队列容量
}

// NewSequentialQueue 初始化队列
func NewSequentialQueue(cap int32) *SequentialQueue {
	return &SequentialQueue{
		Items:  make([]any, 0, cap),
		Length: 0,
		Cap:    cap,
	}
}

// Clear 清空队列
func (queue *SequentialQueue) Clear() {
	queue.Items = []any{}
}

// IsEmpty 判断队列是否为空
func (queue *SequentialQueue) IsEmpty() bool {
	return queue.Length == 0
}

// IsFull 判断队列是否为满
func (queue *SequentialQueue) IsFull() bool {
	return queue.Length == queue.Cap
}

// Push 将元素添加到该队列末尾
func (queue *SequentialQueue) Push(item any) {
	if queue.IsFull() {
		queue.Items = queue.Items[1:]
		queue.Length--
	}

	queue.Items = append(queue.Items, item)
	queue.Length++
}

// Pop 将该队列首元素弹出并返回
func (queue *SequentialQueue) Pop() any {
	if queue.IsEmpty() {
		fmt.Println("queue empty")
		return nil
	}
	item := queue.Items[0]
	queue.Items = queue.Items[1:]
	queue.Length--
	return item
}

// Peek 获取该队列首元素但不出队
func (queue *SequentialQueue) Peek() any {
	if queue.IsEmpty() {
		fmt.Println("queue empty")
		return nil
	}
	return queue.Items[0]
}

// Back 获取该队列尾元素
func (queue *SequentialQueue) Back() any {
	if queue.IsEmpty() {
		fmt.Println("queue empty")
		return nil
	}
	return queue.Items[queue.Length-1]
}

func (queue *SequentialQueue) GetItems() []any {
	return queue.Items
}

func (q *SequentialQueue) GetFloat64Items() []float64 {
	var retItems []float64

	for i := q.Length - 1; i >= 0; i-- {

		switch s := q.Items[i].(type) {
		case float64:
			retItems = append(retItems, s)
		}
	}

	return retItems
}

func (q *SequentialQueue) GetFloat32Items() []float32 {
	var retItems []float32

	for i := q.Length - 1; i >= 0; i-- {

		switch s := q.Items[i].(type) {
		case float32:
			retItems = append(retItems, s)
		}
	}

	return retItems
}

func (q *SequentialQueue) ShowQueue() {

	for i := q.Length - 1; i >= 0; i-- {

		switch s := q.Items[i].(type) {
		case float64:
			//strconv.FormatFloat(s, 'f', -1, 64)
			fmt.Printf(" queue[%d] = %f \t", i, s)
		case float32:
			fmt.Printf(" queue[%d] = %f \t", i, s)
		default:

		}

	}

	fmt.Println()
}

type BombTimeToMul struct {
	MinBombTime int32
	MaxBombTime int32
	BombMul     int32
}

type BombMulToTime struct {
	MinBombMul int32
	MaxBombMul int32
	BombTime   int32
}
