puzzle

package module
v0.0.0-...-a5a7ede Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: MIT Imports: 10 Imported by: 0

README

puzzle-bot

This library is now broken. I do not plan to update it. I added code to compute a dynamic challenge introduced to prove that the user is using a browser, but it seems like message construction was changed. I don't feel like reverse engineering the puzzle website's code again, but people are welcome to try on their own. Sorry!

A library for creating bots for the interactive jigsaw puzzle https://puzzle.aggie.io.

Usage

go run ./cmd/bot \
    --name "Puzzle Guy" \
    --color "#00ff00" \
    --room "ABC123" \
    [action flag]

Where [action flag] is one of the following:

--edges                   Complete the edges of the puzzle
--complete                Complete the entire puzzle
--region (r1,c1):(r2,c2)  Complete the region of the puzzle defined 
                          by the top left and bottom right corners

All Options

Join Options
    --name string           User display name (default "Puzzle Bot")
    --color <hex string>    User display color (default "#00ff00")
    --room string           puzzle.aggie.io room code
    --secret string         puzzle.aggie.io room secret
    
Actions
    --edges                 Solve edges
    --complete              Solve puzzle completely
    --region string         Solve region from (row,col):(row2,col2)

Misc
    --delay <duration>      Delay between actions (default 500µs)
    --force                 Force operation even if root is not found or locked
    --override-version      Override the server version check
    --debug                 Show debug information

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseJSONMessage

type BaseJSONMessage struct {
	Type    string          `json:"type"`
	Users   json.RawMessage `json:"Users"`
	Room    json.RawMessage `json:"Room"`
	MeID    uint16          `json:"id"`
	Version string          `json:"version"`
}

type ChallengeResponseMessage

type ChallengeResponseMessage struct {
	Value uint32
}

func (*ChallengeResponseMessage) Encode

func (*ChallengeResponseMessage) Name

func (m *ChallengeResponseMessage) Name() string

type CombinePiecesMessage

type CombinePiecesMessage struct {
	FirstID  uint16
	SecondID uint16
	X        float32
	Y        float32
}

func (*CombinePiecesMessage) Encode

func (m *CombinePiecesMessage) Encode(state *SessionState) (int, []byte, error)

func (*CombinePiecesMessage) Name

func (m *CombinePiecesMessage) Name() string

type DataView

type DataView []byte

DataView provides an interface to read and write different primitives from a byte array in little endian order. You must ensure that the underlying byte array has a size large enough when writing to it.

func (DataView) Float32

func (view DataView) Float32(offset int) float32

Float32 reads a float32 from the given offset.

func (DataView) PutFloat32

func (view DataView) PutFloat32(val float32, offset int)

PutFloat32 writes a float32 at the given offset.

func (DataView) PutRawBytes

func (view DataView) PutRawBytes(data []byte, offset int)

PutRawBytes copies the bytes from data at the given offset.

func (DataView) PutUint16

func (view DataView) PutUint16(val uint16, offset int)

PutUint16 writes a uint16 at the given offset.

func (DataView) PutUint32

func (view DataView) PutUint32(val uint32, offset int)

PutUint32 writes a uint32 at the given offset.

func (DataView) PutUint8

func (view DataView) PutUint8(val uint8, offset int)

PutUint8 writes a uint8 (single byte) at the given offset.

func (DataView) ReadString

func (view DataView) ReadString(offset int) (string, int)

ReadString reads a length-prefixed string starting at the given offset. Returns the string read and the number of bytes read in total (length of string plus 2 bytes for length prefix).

func (DataView) Uint16

func (view DataView) Uint16(offset int) uint16

Uint16 reads a uint16 from the given offset.

func (DataView) Uint32

func (view DataView) Uint32(offset int) uint32

Uint32 reads a uint32 from the given offset.

func (DataView) Uint8

func (view DataView) Uint8(offset int) uint8

Uint8 reads a uint8 (single byte) from the given offset.

type Group

type Group struct {
	ID      uint16   `json:"id"`
	IDs     []uint16 `json:"ids"`
	Indices []uint16 `json:"indices"`
	Locked  bool     `json:"locked"`
	X       float32  `json:"x"`
	Y       float32  `json:"y"`
}

type JoinMessage

type JoinMessage struct {
	UserName string
	Color    string
	Room     string
	Secret   *string
}

func (*JoinMessage) Encode

func (m *JoinMessage) Encode(state *SessionState) (int, []byte, error)

func (*JoinMessage) Name

func (m *JoinMessage) Name() string

type Message

type Message interface {
	Encode(state *SessionState) (int, []byte, error)
	Name() string
}

type MovePieceMessage

type MovePieceMessage struct {
	ID uint16
	X  float32
	Y  float32
}

func (*MovePieceMessage) Encode

func (m *MovePieceMessage) Encode(state *SessionState) (int, []byte, error)

func (*MovePieceMessage) Name

func (m *MovePieceMessage) Name() string

type Options

type Options struct {
	Room            string
	Secret          string
	UserName        string
	UserColor       string
	Debug           bool
	OverrideVersion bool
}

type PickUpPieceMessage

type PickUpPieceMessage struct {
	ID uint16
	X  float32
	Y  float32
}

func (*PickUpPieceMessage) Encode

func (m *PickUpPieceMessage) Encode(state *SessionState) (int, []byte, error)

func (*PickUpPieceMessage) Name

func (m *PickUpPieceMessage) Name() string

type PongMessage

type PongMessage struct{}

func (*PongMessage) Encode

func (m *PongMessage) Encode(state *SessionState) (int, []byte, error)

func (*PongMessage) Name

func (m *PongMessage) Name() string

type PutDownPieceMessage

type PutDownPieceMessage struct {
	ID uint16
	X  float32
	Y  float32
}

func (*PutDownPieceMessage) Encode

func (m *PutDownPieceMessage) Encode(state *SessionState) (int, []byte, error)

func (*PutDownPieceMessage) Name

func (m *PutDownPieceMessage) Name() string

type Room

type Room struct {
	BoardHeight   int     `json:"boardHeight"`
	BoardWidth    int     `json:"boardWidth"`
	Groups        []Group `json:"groups"`
	HidePreview   bool    `json:"hidePreview"`
	Jitter        float32 `json:"jitter"`
	Name          string  `json:"name"`
	NoLockUnlock  bool    `json:"noLockUnlock"`
	NoMultiSelect bool    `json:"noMultiSelect"`
	Pieces        uint16  `json:"pieces"`
	Rotation      bool    `json:"rotation"`
	Seed          int     `json:"seed"`
	StartTime     int     `json:"startTime"`
	TabSize       float32 `json:"tabSize"`
	Sets          []Set   `json:"sets"`
}

func (*Room) Columns

func (r *Room) Columns() uint16

func (*Room) GroupByID

func (r *Room) GroupByID(id uint16) *Group

func (*Room) PieceHeight

func (r *Room) PieceHeight() float32

func (*Room) PieceWidth

func (r *Room) PieceWidth() float32

func (*Room) Rows

func (r *Room) Rows() uint16

type Session

type Session struct {
	OnJoined func(state *SessionState)
	// contains filtered or unexported fields
}

func NewSession

func NewSession(ctx context.Context, opts Options) (*Session, error)

NewSession creates a new puzzle session with the given options.

func (*Session) CombinePieces

func (s *Session) CombinePieces(id1 uint16, id2 uint16, x float32, y float32)

func (*Session) Exit

func (s *Session) Exit()

Exit closes the puzzle session.

func (*Session) MovePiece

func (s *Session) MovePiece(id uint16, x float32, y float32)

func (*Session) PickUpPiece

func (s *Session) PickUpPiece(id uint16, x float32, y float32)

func (*Session) PutDownPiece

func (s *Session) PutDownPiece(id uint16, x float32, y float32)

func (*Session) Run

func (s *Session) Run(ctx context.Context)

Run begins the read/write loop of the puzzle session. This function will block until the passed context finishes.

type SessionState

type SessionState struct {
	Joined bool
	UserID uint16
	Room   *Room
	Users  []User
}

type Set

type Set struct {
	Rows    uint16  `json:"rows"`
	Columns uint16  `json:"cols"`
	Width   float32 `json:"width"`
	Height  float32 `json:"height"`
}

func (*Set) PieceHeight

func (s *Set) PieceHeight() float32

func (*Set) PieceWidth

func (s *Set) PieceWidth() float32

type User

type User struct {
	ID    uint16 `json:"id"`
	Name  string `json:"name"`
	Color string `json:"color"`
}

Directories

Path Synopsis
cmd
bot

Jump to

Keyboard shortcuts

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