Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 9 First Draft #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions exercise-009-rock/src/rock/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const (

// Game ...
type Game struct {
players []*Player
players []Player
points []int
}

// Add adds a player to the game
func (g *Game) Add(p *Player) {
func (g *Game) Add(p Player) {
g.players = append(g.players, p)
g.points = append(g.points, 0)
}
Expand All @@ -33,7 +33,7 @@ func (g *Game) RoundRobin() {

n := len(g.players)

// For Each Player
// For Each RandoRex
for i := 0; i < n-1; i++ {

// For Each Opponent
Expand Down
56 changes: 52 additions & 4 deletions exercise-009-rock/src/rock/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,65 @@ import (
"math/rand"
)

// Player ...
type Player struct {
type Player interface {
Type() string
Play() int
}

type Flipper struct {
MoveA int
MoveB int
}

func (p Flipper) Type() string {
return "Flipper"
}

func (p Flipper) Play() int {
moves := []int{p.MoveA,p.MoveB}
return moves[rand.Int() % len(moves)]
}

type Obsessed struct {
Move int
}

func (p Obsessed) Type() string {
return "Obsessed"
}

func (p Obsessed) Play() int {
return p.Move
}

type Cyclone struct {
MoveCount int
}

func (p Cyclone) Type() string{
return "Cyclone"
}

func (p Cyclone) Play() int {
p.MoveCount++
moves := []int{Rock,Paper,Scissors}
return moves[p.MoveCount % len(moves)]

}



// RandoRex ...
type RandoRex struct {
}

// Type returns the type of the player
func (p *Player) Type() string {
func (p RandoRex) Type() string {
return "RandoRex"
}

// Play returns a move
func (p *Player) Play() int {
func (p RandoRex) Play() int {
choice := rand.Int() % 3
return choice
}
9 changes: 6 additions & 3 deletions exercise-009-rock/src/rock/rock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ func main() {
game := &Game{}

// Add Players
game.Add(&Player{})
game.Add(&Player{})
game.Add(&Player{})
game.Add(&RandoRex{})
game.Add(&RandoRex{})
game.Add(&Flipper{Rock,Paper})
game.Add(&Obsessed{Paper})
game.Add(&Obsessed{Scissors})
game.Add(&Cyclone{})

// A Thousand Round-Robins!
for i := 0; i < 1000; i++ {
Expand Down