<commit_before>package sim

import (
	"github.com/Queens-Hacks/propagate/sandbox"
	"github.com/Sirupsen/logrus"
)

type tileType int

const (
	dirtTile tileType = iota
	airTile
	plantTile
)

type Location struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type growthRoot struct {
	PlantId int
	Loc     Location
	node    *sandbox.Node
}

type plantInfo struct {
	PlantId int      `json: "plantId"`
	Parent  Location `json: "parent"`
	Age     int      `json: "age"`
}

type tile struct {
	T     tileType   `json:"tileType"`
	Plant *plantInfo `json:"plant"`
}

type plant struct {
	Color  string `json:"color"`
	Source string `json:"source"`
	Author string `json:"author"`
}

type state struct {
	World  [][]tile `json:"world"`
	Plants []plant  `json:"plants"`
	roots  []growthRoot
}

type newStateInfo struct {
	ch   <-chan sandbox.NewState
	root *growthRoot
}

const sunAccumulationRate int = 10

func mkWorldState(s *state, _ *growthRoot) {
	var ws sandbox.WorldState

	worldState.Lighting[sandbox.Left] = 0
	worldState.Lighting[sandbox.Right] = 0
	worldState.Lighting[sandbox.Up] = 0
	worldState.Lighting[sandbox.Down] = 0

	return ws
}

func applyChanges(s *state, root *growthRoot, in sandbox.NewState) {
	newX := root.Loc.X
	newY := root.Loc.Y

	// XXX newState should actually contain information about the type of
	// operation performed
	if newState.MoveDir == sandbox.Left {
		newX -= 1
	} else if newState.MoveDir == sandbox.Right {
		newX += 1
	} else if newState.MoveDir == sandbox.Up {
		newY -= 1
	} else if newState.MoveDir == sandbox.Down {
		newY += 1
	} else {
		continue
	}

	// Can't move there, it's out of bounds!
	if newY < 0 || newY > len(s.World) {
		logrus.Info("newY out of bounds")
		continue
	}
	if newX < 0 || newX > len(s.World[newY]) {
		logrus.Info("newY out of bounds")
		continue
	}

	// Update the tile entry in the world map with the new growth
	tile := &s.World[newY][newX]
	tile.T = plantTile
	tile.Plant = &plantInfo{
		PlantId: response.root.PlantId,
		Parent:  response.root.Loc,
		Age:     0,
	}

	// Move the growth root to the new location
	response.root.Loc.X = newX
	response.root.Loc.Y = newY
}

// This is called by a timer every n time units
func SimulateTick(s *state) {
	responses := make([]newStateInfo, len(s.roots))

	// Tell each root to run until the next move operation
	for i := range s.roots {<commit_msg>My code is flawless<commit_after>package sim

import (
	"github.com/Queens-Hacks/propagate/sandbox"
	"github.com/Sirupsen/logrus"
)

type tileType int

const (
	dirtTile tileType = iota
	airTile
	plantTile
)

type Location struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type growthRoot struct {
	PlantId int
	Loc     Location
	node    *sandbox.Node
}

type plantInfo struct {
	PlantId int      `json: "plantId"`
	Parent  Location `json: "parent"`
	Age     int      `json: "age"`
}

type tile struct {
	T     tileType   `json:"tileType"`
	Plant *plantInfo `json:"plant"`
}

type plant struct {
	Color  string `json:"color"`
	Source string `json:"source"`
	Author string `json:"author"`
}

type state struct {
	World  [][]tile `json:"world"`
	Plants []plant  `json:"plants"`
	roots  []growthRoot
}

type newStateInfo struct {
	ch   <-chan sandbox.NewState
	root *growthRoot
}

const sunAccumulationRate int = 10

func mkWorldState(s *state, _ *growthRoot) sandbox.WorldState {
	var ws sandbox.WorldState

	ws.Lighting[sandbox.Left] = 0
	ws.Lighting[sandbox.Right] = 0
	ws.Lighting[sandbox.Up] = 0
	ws.Lighting[sandbox.Down] = 0

	return ws
}

func applyChanges(s *state, root *growthRoot, in sandbox.NewState) {
	newX := root.Loc.X
	newY := root.Loc.Y

	// XXX in should actually contain information about the type of
	// operation performed
	if in.MoveDir == sandbox.Left {
		newX -= 1
	} else if in.MoveDir == sandbox.Right {
		newX += 1
	} else if in.MoveDir == sandbox.Up {
		newY -= 1
	} else if in.MoveDir == sandbox.Down {
		newY += 1
	} else {
		return
	}

	// Can't move there, it's out of bounds!
	if newY < 0 || newY > len(s.World) {
		logrus.Info("newY out of bounds")
		return
	}
	if newX < 0 || newX > len(s.World[newY]) {
		logrus.Info("newY out of bounds")
		return
	}

	// Update the tile entry in the world map with the new growth
	tile := &s.World[newY][newX]
	tile.T = plantTile
	tile.Plant = &plantInfo{
		PlantId: root.PlantId,
		Parent:  root.Loc,
		Age:     0,
	}

	// Move the growth root to the new location
	root.Loc.X = newX
	root.Loc.Y = newY
}

// This is called by a timer every n time units
func SimulateTick(s *state) {
	responses := make([]newStateInfo, len(s.roots))

	// Tell each root to run until the next move operation
	for i := range s.roots {
{'fraction_non_alphanumeric': 0.12335844994617869, 'fraction_numerical': 0.005597416576964478, 'mean_word_length': 3.3665413533834587, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1943045', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1698, 'n_words': 502}