Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"fmt"
"reflect"
)
const NORMALLY_EFFECTIVE = 1.0
const SUPER_EFFECTIVE = 2.0
const NOT_VERY_EFFECTIVE = 0.5
type PokemonType interface { }
type Normal struct{}
func newNormal() Normal { return Normal{} }
type Fire struct{}
func newFire() Fire { return Fire{} }
func eff(atk *Normal, def *Normal) float32 { return NORMALLY_EFFECTIVE }
func eff(atk *Fire, def *Fire) float32 { return NOT_VERY_EFFECTIVE }
func main() {
atk := newNormal()
def := newFire()
fmt.Printf("Fight! \n")
fmt.Printf("attack [%s] -> defense [%s]\n", reflect.TypeOf(atk), reflect.TypeOf(def))
fmt.Printf("it's %d effective!", eff(atk, def))
}
package main
import (
"fmt"
"reflect"
)
const NORMALLY_EFFECTIVE = 1.0
const SUPER_EFFECTIVE = 2.0
const NOT_VERY_EFFECTIVE = 0.5
type PokemonType interface { eff(*PokemonType) float32 }
type Normal struct{}
func newNormal() Normal { return Normal{} }
func (n *Normal) eff(def *Normal) float32 { return NORMALLY_EFFECTIVE }
type Fire struct{}
func newFire() Fire { return Fire{} }
func (n *Fire) eff(def *Fire) float32 { return NOT_VERY_EFFECTIVE }
func fight(atk PokemonType, def PokemonType) {
fmt.Sprintf("Fight! ")
fmt.Sprintf("attack [%s] -> defense [%s]", reflect.TypeOf(atk), reflect.TypeOf(def))
fmt.Sprintf("It's
}
func main() {
normal := newNormal()
fire := newFire()
fight(normal, fire)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment