package main import ( "fmt" "time" ) //This is a simple example of Go routines //Our program executes some calculus using concurrency //We're calculating the points of each player in the final turn // Characters -> Witch, Orc, Warrior // Features -> Strength, Speed, Magic // Actions -> Attack, Defense, Run //Action -> commons actions type Action struct { attack int16 defense int16 speed int16 } //Witch -> represents a Witch type Witch struct { id string name string magic int16 actions Action } //Orc -> represents an Orc type Orc struct { id string name string strength int16 actions Action } //Warrior -> represents a Warrior type Warrior struct { id string name string speed int16 tatics int16 actions Action } //Ranking -> represents the ranking type Ranking struct { total int16 timestamp int64 players []RankingPosition } //RankingPosition -> represents a position type RankingPosition struct { name string id string points int16 position int16 } func executeRandomTurn() []RankingPosition { warrior := Warrior{ id: "warrior_id", name: "San Patrick", tatics: 20, actions: Action{attack: 12, defense: 12, speed: 23}} witch := Witch{ id: "witch_id", name: "Zechyn Magus", magic: 34, actions: Action{attack: 12, defense: 8, speed: 23}} orc := Orc{ id: "orc_id", name: "Swargeen", strength: 44, actions: Action{attack: 25, defense: 18, speed: 6}} var positions []RankingPosition positions = append(positions, RankingPosition{name: warrior.name, id: warrior.id, points: (warrior.tatics * warrior.actions.attack), position: 0}) positions = append(positions, RankingPosition{name: witch.name, id: witch.id, points: (witch.magic * witch.actions.defense), position: 0}) positions = append(positions, RankingPosition{name: orc.name, id: orc.id, points: (orc.strength * orc.actions.speed), position: 0}) return positions } func getRanking(positions []RankingPosition) Ranking { var t int16 for i, s := range positions { fmt.Println(i, s) t += s.points } ranking := Ranking{timestamp: (time.Now().UnixNano() / 1000000), players: positions, total: t} return ranking } func main() { positions := executeRandomTurn() ranking := getRanking(positions) fmt.Println("Ranking", ranking) }