Skip to content

Instantly share code, notes, and snippets.

@QuantumFractal
Last active July 18, 2021 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuantumFractal/0e8e708058e9ffa6f58beef4595a82da to your computer and use it in GitHub Desktop.
Save QuantumFractal/0e8e708058e9ffa6f58beef4595a82da to your computer and use it in GitHub Desktop.
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