Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/scripts/test-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ $required = @(
'TestAnalyzeRefusalsDoNotWriteState',
'TestAnalyzeDoesNotRedirectAnUnreadableExactGame',
'TestPlayNowCutsAMaxSearchShort',
'TestReplayAnalysisFromTheMenu',
'TestStudyNoteSurvivesLeavingAndResizing'
)
$missing = @($required | Where-Object { -not $passes.ContainsKey($_) })
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
move: completed depth, nodes and time in all, and stop reason. A status line
too narrow for all of them gives up whole items, the stop reason before the
time and the nodes, and always keeps the move and its completed depth.
- `?` in the saved-game replay analyses the entry on screen in the background:
the placement-only badge, the recommended hole as the engine's choice under a
bounded search (never a proven best move), its explanation, up to four
candidates with exact/upper/lower/unscored scores, and the completed work with
its stop reason. Time and cancellation stops are marked not reproducible, and
a finished position gets no recommendation. Any seek or leaving cancels the
search and discards its result, `?` again cancels or dismisses, the analysed
position is a copy, and nothing is written. It works regardless of hint
settings, for finished and imported games alike. The bottom line carries the
analysis at every size; a narrow one gives up `not proven` before the badge,
keeping the hole and its placement-only badge whole.
- Study notes and bookmarks in the replay viewer: `m` bookmarks the selected
entry and `e` writes a one-line note on it, shown in the panel and marked in
the entry list with `*` and `#`. They are kept per game, record digest and
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ twixtui help # every command, with what

| | |
| --- | --- |
| [Play a bot](docs/MANUAL.md#playing-a-bot) | Four effort tiers: `beginner`, `intermediate`, a clock-bounded `pro`, and `max`, the largest effort on offer. Hints use `max`'s placement-only search under a two-second guard: advice, not a proof of best play. |
| [Play a bot](docs/MANUAL.md#playing-a-bot) | Four effort tiers: `beginner`, `intermediate`, a clock-bounded `pro`, and `max`, the largest effort on offer. Hints use `max`'s placement-only search under a two-second guard: advice, not a proof of best play. While the bot thinks, its completed depth is shown and `esc` makes it play now. |
| [Hotseat](docs/MANUAL.md#hotseat) | Two players, one terminal, alternating turns. |
| [Remote play](docs/MANUAL.md#remote-play) | Direct, through a relay you or your opponent runs, or by correspondence with no live connection at all. |
| [Learn it](docs/MANUAL.md#the-tutorial) | Seven lessons taught by playing them, and a five-step introduction on [first run](docs/MANUAL.md#the-first-run). |
| [Profiles & standings](docs/MANUAL.md#profiles) | Local names with no passwords, selectable [standings and player histories](docs/MANUAL.md#the-leaderboard), and verified links back to saved-game replays. |
| [Review a game](docs/MANUAL.md#reviewing-saved-games) | A numbered entry list, `:` to jump to an entry, and the winning chain highlighted at the final position. Read-only, including imported records. |
| [Review a game](docs/MANUAL.md#reviewing-saved-games) | A numbered entry list, `:` to jump to an entry, the winning chain at the final position, `?` for a bounded engine reading of the entry on screen, and bookmarks and one-line notes (`m`, `e`) kept beside the game. Records, including imported ones, are never changed. |
| [Analyse a position](docs/MANUAL.md#position-analysis) | Read-only analysis of a saved game, record or move list, with time/node budgets, explicit score bounds, and text or JSON output. |
| [Honest rulesets](docs/MANUAL.md#rulesets) | `std`, `pp` and `classic` make each historical disagreement an explicit setting; boards from 6×6 to 48×48. |
| [Themes & cover art](docs/MANUAL.md#themes) | Four colour schemes, and the [1962 box lid](docs/MANUAL.md#the-cover) drawn beside the menu in character cells. |
Expand Down
69 changes: 59 additions & 10 deletions docs/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ none of those.
| `1`-`8` | Only in link mode: toggle the link in that direction. |
| `esc` | Leave link mode. Otherwise, while a bot is searching for its move: play now, with the search it has finished. |
| `a` | Abort the turn: the board goes back to how it stood when your turn began. |
| `?` | In a bot game: the move the bot would play, and why. |
| `?` | In a bot game: the move the bot would play, and why. In a saved-game replay: the engine's reading of the entry on screen (see [Reviewing saved games](#reviewing-saved-games)). |
| `i` | In a bot game: the figures of the search behind the bot's last move. Offered once the bot has moved, and not while it is searching. |
| `s` | Take the swap option, while it is on offer. |
| `d` | Offer a draw, or accept the one on offer. |
Expand All @@ -349,9 +349,10 @@ reopening the saved game. `ctrl+c` still ends the whole program, even when

The replay viewer reuses the movement keys above for stepping through a record
and adds keys of its own, listed under [Reviewing saved games](#reviewing-saved-games):
`:` jumps to an entry, `m` bookmarks the selected entry and `e` writes a note on
it. While a note is being written every printable key is text, and the key
bound to `enter` above is the one that saves it.
`:` jumps to an entry, `m` bookmarks the selected entry, `e` writes a note on
it and `?` analyses it (the `?` row above). While a note is being written every
printable key is text, `?` included, and the key bound to `enter` above is the
one that saves it.

## Playing a bot

Expand Down Expand Up @@ -901,6 +902,7 @@ shows both the entry counter and the number of moves played.
| `:` | Type an entry number; `enter` jumps and `esc` cancels the input. |
| `m` | Bookmark the selected entry, or take its bookmark off. Saved at once. |
| `e` | Write or edit the selected entry's note; `enter` saves and `esc` cancels without saving. |
| `?` | Analyse the entry on screen; while that analysis runs, cancel it; once it is shown, put it away. |
| `q` / `esc` | Leave the viewer when not editing the entry number or a note. |
| `ctrl+c` | End the program. |

Expand All @@ -919,8 +921,53 @@ Replay validates the whole record before opening and retains one mutable board,
not a board snapshot per entry. Small backward steps use undo; longer backward
seeks rebuild the requested prefix to avoid repeatedly scanning draw-offer
history. Reviewing never changes the stored record or ratings. Variations
are not part of this viewer; engine analysis is available through the
separate `analyze` commands below, not as an interactive replay action.
are not part of this viewer.

`?` asks the engine about the position at the selected entry, in the
background: the keys keep working, and the panel shows a running indicator and,
once a search iteration has finished, the depth and nodes of that completed
work. The analysis is the same one `twixtui analyze` runs with its default
two-second guard (see [Position analysis](#position-analysis)), and the panel
reports it in the same terms, most important first, so a short panel keeps the
badge and the choice and drops the end of the block. The badge and the choice,
or the running indicator, are given rows before the record's own details, so a
panel with only a few rows to spare still shows them; only the notes come
before them — an open note input, a refusal, or the first lines of the selected
entry's bookmark and note (see [Notes and bookmarks](#notes-and-bookmarks)). The
bottom line says where the analysis stands as well — `analysing` and the time
so far, the chosen hole with its `placement-only` badge and `not proven`, or
that it was canceled, failed or has no move to advise — after any refusal from
the notes and before the entry counter and the keys, and on a terminal too
small for a panel it is the only place the analysis appears. A bottom line too
narrow for all of the choice gives up `not proven` first and keeps the hole and
its badge whole, even for a four-character hole such as `AA10` at twenty
columns. The block reads, in order:

- the `placement-only` policy badge, and the recommended hole as **the engine's
choice under a bounded search, not a proven best move**;
- the engine's own headline and detail for that choice;
- up to four candidates with their scores in search units, each marked `exact`,
`at most`/`at least` for a bound, or `unscored` with no number at all;
- the completed work — depth, nodes, elapsed time — and why the search stopped.
A search stopped by the time guard or an interruption is marked not
reproducible.

The recommended hole and the holes the explanation refers to are marked on the
board, only while the entry they were read from is on screen. Any movement —
stepping, jumping five, the ends, or a typed entry number — cancels a search
still running and discards a result already shown, and so does leaving the
viewer; a result that arrives after that is dropped, so an analysis is never
shown against a position it was not computed for. Pressing `?` again stops a
running search (the panel says it was canceled) or puts a shown result away.
A finished position, such as the final entry of a won game, gets no
recommendation: the panel says the game is over at that entry.

Replay analysis is an explicit review action. It works on finished and imported
games alike, whether or not hints were offered when the game was played and
whatever the machine's hint setting is, analyses a copy of the position, and
writes nothing to disk: an analysis is not kept in the notes.
It is not run in the background while stepping; results are not kept between
seeks.

#### Notes and bookmarks

Expand All @@ -935,9 +982,9 @@ marked entries a column of their own once any exist: `*` for a bookmark and `#`
for a note, as characters rather than colours. A note is one line of at most
8 KiB of UTF-8; a longer paste is refused whole rather than cut, and line
breaks in a paste become spaces. While the note input is open every printable
key is text, so `q`, `h` or `:` are typed rather than acted on. Text read from
the file is drawn inert: control characters and escape sequences are shown as
plain text or dropped, never obeyed, and a note written with line breaks by
key is text, so `q`, `h`, `:` or `?` are typed rather than acted on. Text read
from the file is drawn inert: control characters and escape sequences are shown
as plain text or dropped, never obeyed, and a note written with line breaks by
another program keeps them unless you edit them away.

Notes are attached to the record's digest as well as to the game ID, and the
Expand Down Expand Up @@ -966,7 +1013,9 @@ damaged file, and the file is left as it was.

Analyse a saved game, a record file (or standard input), or a position written in
the game's notation. No profile is required, and analysis does not write games,
ratings, profiles or configuration.
ratings, profiles or configuration. The same analysis, under the default
two-second guard, is available interactively with `?` in the replay viewer (see
[Reviewing saved games](#reviewing-saved-games)).

```
twixtui analyze position --size 12 --moves 'B1; L2; C3' --nodes 10000
Expand Down
79 changes: 69 additions & 10 deletions internal/app/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type ReplayScreen struct {
stuck string
// jump is the entry-number input, open only while a number is being typed.
jump entryJump
// analysis is the engine's reading of the entry on screen, once the player
// has asked for one, and analyser is what reads it: bot.Analyze unless a
// test has put something else in its place.
analysis replayAnalysis
analyser replayAnalyser
// notes are the player's notes and bookmarks on this game's entries, and
// the note input while one is being written. See replay_study.go.
notes replayNotes
Expand Down Expand Up @@ -201,7 +206,8 @@ var replayKeys = []replayKey{
{ui.ActEdgeBottom, nil, "ends", func(s *ReplayScreen) tea.Cmd { s.seek(s.entries()); return nil }},
{ui.ActNone, []string{"m"}, "mark", func(s *ReplayScreen) tea.Cmd { s.toggleBookmark(); return nil }},
{ui.ActNone, []string{"e"}, "note", func(s *ReplayScreen) tea.Cmd { s.openNoteEditor(); return nil }},
{ui.ActQuit, []string{"esc"}, "leaves", func(*ReplayScreen) tea.Cmd { return Back() }},
{ui.ActNone, []string{"?"}, "analyse", func(s *ReplayScreen) tea.Cmd { return s.toggleAnalysis() }},
{ui.ActQuit, []string{"esc"}, "leaves", func(s *ReplayScreen) tea.Cmd { s.analysis.drop(); return Back() }},
}

// replayHints renders the footer's key parts, taking the labels from the keymap
Expand Down Expand Up @@ -275,6 +281,10 @@ func NewReplayScreen(d Deps, saved gamestore.Saved) (Screen, error) {
// Init satisfies tea.Model.
func (s *ReplayScreen) Init() tea.Cmd { return nil }

// Depart stops an analysis still running when the program ends with the review
// open: the engine would be working for a screen that is no longer there.
func (s *ReplayScreen) Depart() { s.analysis.drop() }

// Update satisfies tea.Model.
func (s *ReplayScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch m := msg.(type) {
Expand All @@ -299,6 +309,10 @@ func (s *ReplayScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
s.jump.insert(strings.TrimSpace(m.Content))
}
}
case replayAnalysisDoneMsg:
s.analysis.finish(m)
case replayAnalysisTickMsg:
return s, s.analysis.tick(m)
}
return s, nil
}
Expand Down Expand Up @@ -388,6 +402,10 @@ func (s *ReplayScreen) jumpToEntry() {
// says so in the panel, rather than leaving a board that is neither where the
// player was nor where they asked to be.
func (s *ReplayScreen) seek(to int) {
// An analysis belongs to the position it was asked about. Moving through the
// record cancels one still running and puts away one already shown, so that
// neither can be read against a position it was not computed for.
s.analysis.drop()
if err := s.cursor.seek(to); err != nil {
s.stuck = err.Error()
return
Expand Down Expand Up @@ -431,6 +449,12 @@ func (s *ReplayScreen) View() tea.View {
if s.step() == s.entries() {
s.board.Highlights = s.winning
}
// An analysis marks the holes it refers to, but only on the position it
// read: anywhere else they would be advice about a different board. A
// finished position has nothing to advise, so the chain stays where it is.
if marks := s.analysis.highlights(s.step()); len(marks) > 0 {
s.board.Highlights = marks
}
board := s.board.Render(s.current(), st, arr.BoardAvailW, arr.BoardAvailH)
panel := s.panel(arr.PanelW, arr.PanelH)
status := s.status(arr.Width)
Expand All @@ -452,19 +476,20 @@ func (s *ReplayScreen) focus() (game.Point, bool) {
return game.Point{}, false
}

// status is the bottom row: where in the record the player is, then what the
// keys do, dropped from the end when the terminal is too narrow for all of it.
// status is the bottom row: what the player is doing, then where in the record
// they are, then what the keys do, dropped from the end when the terminal is
// too narrow for all of it.
//
// At the widths that have no room for a panel it is the whole of the interface,
// so an open input is drawn here as well as there, and what is wrong with a
// number, or what the notes refused, comes before the counter and the keys,
// which are what a narrow line gives up first.
// so an open input and the analysis are drawn here as well as there, and what
// is wrong with a number, or what the notes refused, comes before the analysis,
// the counter and the keys, which a narrow line gives up from the end.
func (s *ReplayScreen) status(width int) string {
// These are record entries rather than moves: a draw offer is an entry that
// changes nothing on the board, so counting them as moves disagreed with
// every other surface's move count.
counter := fmt.Sprintf("step %d of %d", s.step(), s.entries())
parts := make([]string, 0, len(s.hints)+3)
parts := make([]string, 0, len(s.hints)+4)
hints := s.hints
switch {
case s.jump.open:
Expand All @@ -482,6 +507,13 @@ func (s *ReplayScreen) status(width int) string {
if note := s.studyStatus(); note != "" {
parts = append(parts, truncateText(note, width))
}
// The analysis arrives fitted to the row: brief gives up whole items before
// it cuts anything, and marks what it does cut, which the frame pulls back
// to a whole word. A part left wider than the row would be clipped at the
// edge of the frame instead, unmarked, wherever the edge fell.
if a := s.analysisStatus(width); a != "" {
parts = append(parts, a)
}
parts = append(parts, counter)
return hintLine(width, append(parts, hints...)...)
}
Expand All @@ -494,7 +526,10 @@ func (s *ReplayScreen) status(width int) string {
// every row on titles and results would leave a review with nothing to review.
// The study block comes next: it is built for every row the list leaves it and
// sets aside the rows it needs, so an open note input or a refusal is drawn
// whole wherever there is room for it, and the prose has what is left.
// whole wherever there is room for it. An analysis the player has asked for is
// promised its lead after that, ahead of the record's details: a panel that
// spent its last rows on those showed nothing at all after ?, not even that a
// search was running. The prose has what is left.
func (s *ReplayScreen) panel(width, height int) []string {
if width <= 0 || height <= 0 {
return nil
Expand All @@ -504,14 +539,38 @@ func (s *ReplayScreen) panel(width, height int) []string {
out = append(out, clampLines(s.jump.lines(shellStyles(s.deps), width), height)...)
list := s.listShare(height)
study := s.studyLines(width, s.studyRoom(width, height))
if room := height - len(out) - list - s.studyReserve(width, study); room > 1 {
kept := s.studyReserve(width, study)
// The analysis's lead is set aside with the blank line that closes it.
lead := s.analysisLead(width)
reserve := 0
if lead > 0 {
reserve = lead + 1
}
if room := height - len(out) - list - kept - reserve; room > 1 {
out = append(out, clampLines(s.describe(width), room-1)...)
out = append(out, "")
}
if room := height - len(out) - list; room > 1 && len(study) > 0 {
out = append(out, cutRows(study, room-1, width)...)
// The block is drawn in every row it set aside, even where that leaves
// the analysis's lead none: an open note input sets aside all of its
// rows, and they are the studyRoom a stale note's save is judged on
// (storedOnScreen), so an input drawn in fewer would let a save replace
// a note the player never saw whole. Rows the prose left beyond both
// reserves go to the block, and what it does not use to the analysis.
out = append(out, cutRows(study, max(room-reserve, kept)-1, width)...)
out = append(out, "")
}
if room := height - len(out) - list; room > 0 {
// The closing blank line is given up before any of the lead is: in the
// smallest panel the badge and the state of the search sit directly on
// the list, which beats a badge that says nothing about the search.
if block := s.analysisLines(width, max(room-1, min(room, lead))); len(block) > 0 {
out = append(out, block...)
if len(out) < height-list {
out = append(out, "")
}
}
}
return append(out, s.entryList(width, height-len(out))...)
}

Expand Down
Loading
Loading