amazonsChess

package module
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 9 Imported by: 1

README

amazonsChess

amazonsChess in go

contributor

MurInJ

function

amazonsChess have follows functions as so far:

  • play one round game quickly
  • randomly play
  • get chess history after one round
  • use AI written by yourself
  • colorful terminal and hidden option

install

go get github.com/murInJ/amazonsChess

qiuck start

The following code can achieve the effect in the preview

game := amazonsChess.Game{CurrentPlayer: 1}

game.Start(true)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DIR = [][]int{{0, 1}, {1, 0}, {1, 1}, {0, -1}, {-1, 0}, {-1, -1}, {-1, 1}, {1, -1}}

Functions

func Clone

func Clone(a, b interface{}) error

Clone 完整复制数据

func NewBoard

func NewBoard() []int

Types

type ChessMove

type ChessMove struct {
	Start    int `json:"start,omitempty"`
	End      int `json:"end,omitempty"`
	Obstacle int `json:"obstacle,omitempty"`
}

func NewChessMove added in v1.0.3

func NewChessMove(start, end, obstacle int) *ChessMove

func (ChessMove) Equal

func (m ChessMove) Equal(move ChessMove) bool

func (ChessMove) GetVal added in v1.0.4

func (m ChessMove) GetVal() []int

type Game

type Game struct {
	CurrentPlayer int                    `json:"current_player,omitempty"`
	CurrentState  *State                 `json:"current_state,omitempty"`
	Winner        int                    `json:"winner,omitempty"`
	Ai1Handler    func(*State) ChessMove `json:"ai_1_handler,omitempty"`
	Ai2Handler    func(*State) ChessMove `json:"ai_2_handler,omitempty"`
}

func NewGame added in v1.0.7

func NewGame() (*Game, error)

func (*Game) GameOver

func (g *Game) GameOver() bool

func (*Game) GetMove

func (g *Game) GetMove(state *State) ChessMove

func (*Game) LogGenerate

func (g *Game) LogGenerate() ([]byte, error)

func (*Game) Reset

func (g *Game) Reset(currentPlayer int) error

Reset reset a game, must call it befor a round start if not by calling function start

func (*Game) Start

func (g *Game) Start(isShow bool) [][]byte

type Log

type Log struct {
	GameState State `json:"game_state"`
	Status    int   `json:"status"`
	Winner    int   `json:"winner"`
}

Log @Param GameState 棋盘状态 @Param status 记录类型 0:未结束 1:已结束 @Param winner 胜利方 (1、-1)

type State

type State struct {
	Board         []int `json:"board,omitempty"`
	CurrentPlayer int   `json:"current_player,omitempty"`
}

func NewState added in v1.0.5

func NewState(board *[]int, currentPlayer int) *State

func (*State) GetActionSpace

func (s *State) GetActionSpace(loc int) ([]int, error)

GetActionSpace get action space of diffrent direction by a loc

func (*State) GetValid

func (s *State) GetValid() []ChessMove

func (*State) PrintState

func (s *State) PrintState()

func (*State) RandomMove added in v1.0.3

func (s *State) RandomMove() (*State, error)

func (*State) StateMove

func (s *State) StateMove(move ChessMove) (*State, error)

func (*State) Str added in v1.0.4

func (s *State) Str() string

NewState 3 6 30 39 60 69 93 96 loc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL