Last active
July 18, 2021 09:45
-
-
Save QuantumFractal/0e8e708058e9ffa6f58beef4595a82da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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