From: El O. De M. <obs...@gm...> - 2025-07-22 18:41:44
|
Yes, in wxMaxima That works. Thanks for the tip El mar, 22 jul 2025 a las 13:20, Barton Willis (<wi...@un...>) escribió: > Are you using wxMaxima? If so, trying to look in the configuration menu > for "Worksheet." Under that, look for 'Interaction" and uncheck "Offer > answer for questions known from previous runs." > > If that works, please let us know. > > --Barton > ------------------------------ > *From:* El Observatorio De Matemática <obs...@gm...> > *Sent:* Tuesday, July 22, 2025 10:56 AM > *To:* <max...@li...> < > max...@li...> > *Subject:* [Maxima-discuss] About the behaviour of read > > Caution: Non-NU Email > > Hi > > I have used the command read many times and have noticed something like > data persistence. > You can try once the following attempted tic, tac, toe implementation, > which uses read. > --> /* Tic-Tac-Toe game implementation */ > > /* Initialize the game state */ > /*grid: matrix(["", "", ""], ["", "", ""], ["", "", ""])$*/ > grid:genmatrix(lambda([x,y],""),3,3)$ > player: X$ > --> /* Function to make a move */ > make_move(my_row,my_col) := > block(if grid[my_row][my_col] = "" then > (grid[my_row][my_col]: player, > player: if player = X then O else X) > else > (print("Invalid move, try again.")))$ > --> diagonalp(grid):=is(unique(makelist(grid[i,i],i,3))#[""] and > length(unique(makelist(grid[i,i],i,3)))=1)$ > --> antidiagonalp(grid):=is(unique(makelist(grid[i,4-i],i,3))#[""] and > length(unique(makelist(grid[i,4-i],i,3)))=1)$ > --> rowp(grid):=block( > L:[], > for i from 1 thru 3 do if unique(flatten(args(row(grid,i))))#[""] and > length(unique(flatten(args(row(grid,i)))))=1 then > push(row(grid,i),L), > if L#[] then true > )$ > --> columnp(grid):=block( > L:[], > for i from 1 thru 3 do if unique(flatten(args(col(grid,i))))#[""] and > length(unique(flatten(args(col(grid,i)))))=1 then > push(col(grid,i),L), > if L#[] then true > )$ > --> check_winner(grid):=is(diagonalp(grid) or antidiagonalp(grid) or > rowp(grid) or columnp(grid))$ > --> /* Game loop */ > tictactoe():=block( > runner:true, > while runner do ( > print(grid), > [my_row,my_col]: read("Enter row and col (1-3) as a list: "), > make_move(my_row,my_col), > winner: check_winner(grid), > if winner then ( > print("Player ", if player = X then O else X, " wins!"), > runner:false), > if not member("", flatten(args(grid))) then ( > print("It's a draw!"), > runner:false > ) > ) > )$ > --> reset_game() := ( > grid: genmatrix(lambda([x,y],""),3,3), > player: X > )$ > --> tictactoe(); > > After one play, if another game is initialized, a "suggestion" is shown > for the player, namely the initial for the previous play. I mean, Is it > good that while using read some "options" appear? > > There is another way to see the persistence behaviour. > I could use vscode copilot in agent mode to ask it to do changes in .wxm > files. One file in which I ask for changes was one with the code above, but > after a play of tic, tac, toe additional lines were added, like: > /* [wxMaxima: input start ] */ > columnp(grid):=block( > L:[], > for i from 1 thru 3 do if unique(flatten(args(col(grid,i))))#[""] and > length(unique(flatten(args(col(grid,i)))))=1 then > push(col(grid,i),L), > if L#[] then true > )$ > /* [wxMaxima: input end ] */ > > or > > /* [wxMaxima: question start ] */ > <math><st>Enter column (1-3): </st><st> </st></math> > /* [wxMaxima: question end ] */ > /* [wxMaxima: answer start ] */ > 2;3;3;2;1; > /* [wxMaxima: answer end ] */ > > These lines persisted in vscode even if the wxmaxima code was returned to > an unevaluated form (all cells not evaluated) and saved. > > If this kind of behavior is wanted, let me know > > best regards > > -- > https://github.com/Observatorio-de-Matematica > <https://urldefense.com/v3/__https://github.com/Observatorio-de-Matematica__;!!PvXuogZ4sRB2p-tU!AueoHCgwSkiFcHLdq05Vw_EiLoIwcQKMtHZt04UcdfhWQQL_Q7VwYsSKWTZRE5zMiVIGqAvDx4-T42SqB9FBb07QLQ$> > |