Test Post

this is a hugo static site, built with builds.sr.ht, and deployed on sourcehut pages.

An Example Code Block

this code block is an excerpt from my multiplayer game of go.

// Play the given stone at the given intersection.
// Returns an array of stones added, an array of stones removed, and
// potentially an error value.
func (game *GoGame) Play(move GoMove) ([]GoMove, []GoMove, error) {
	oppositeColor, err := SwapColor(move.Stone)
	if err != nil {
		// An invalid stone was provided.
		return nil, nil, err
	}

	if !IsOnBoard(game.MaxCoord, move.At) {
		// The given intersection is invalid.
		return nil, nil, errors.New("invalid intersection")
	}

	if game.Get(move.At) != Empty {
		// The intersection is already occupied.
		return nil, nil, errors.New("intersection is already occupied")
	}

	var added []GoMove
	var removed []GoMove

	moveOffset := offsetOf(game.MaxCoord, move.At)

	// Place the stone.
	game.justPlaceStone(move.Stone, moveOffset)
	added = append(added, move)

	// Potentially capture any of the opponent's chains around this stone.
	for _, offset := range game.neighbors[moveOffset] {
		if game.getOffset(offset) == oppositeColor {
			// This is an opponent's stone.
			captured := game.maybeCaptureChain(fromOffset(game.MaxCoord, offset))

			for _, capture := range captured {
				removed = append(removed, capture)
			}
		}
	}

	// Potentially capture any of the player's own chains around this stone.
	for _, offset := range game.neighbors[moveOffset] {
		if game.getOffset(offset) == move.Stone {
			// This is one of the player's own stones.
			captured := game.maybeCaptureChain(fromOffset(game.MaxCoord, offset))

			for _, capture := range captured {
				removed = append(removed, capture)
			}
		}
	}

	stringified := string(game.Board)

	if _, ok := game.history[stringified]; ok {
		// This board state has occurred before.
		return nil, nil, errors.New("move violates superko")
	}

	// Add this board state to the history.
	game.history[stringified] = struct{}{}

	return added, removed, nil
}

wesley nelson

software engineer currently working remotely for shipt


an initial post to test this new blog

By wesley nelson, 2022-08-22