home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 68,886 of 68,980   
   Tom Del Rosso to All   
   Master Mind (1/2)   
   24 Feb 25 12:10:52   
   
   From: fizzbintuesday@that-google-mail-domain.com   
      
   I was looking for something on github and stumbled upon 2 different   
   batch versions of the MASTERMIND game. It might be my favorite game, but   
   I didn't like either of those versions. Neither could play the 4-of-6   
   form of the game, or allow repetition, like the form Donald Knuth used   
   for his solver algorithm, and neither showed the score as a row of pegs   
   like the physical board game does.   
      
   So I was compelled to write my own. It's quite addictive.   
      
   Line wrapping is marked with +++ of course.   
      
   +++@echo off   
   +++rem  MASTER.CMD   
   +++rem  Master Mind game by Tom Del Rosso Nov 25, 2024   
   +++setlocal   
   +++title MASTER MIND   
   +++echo;   
   +++echo MASTER MIND   
   +++   
   +++rem  ****************** PROMPT DEFAULTS ******************   
   +++rem  These settings are chosen by just pressing enter at the prompts.   
   +++rem  Every game prompts again and, if you enter a new value,   
   +++rem  it becomes the default for subsequent games.   
   +++rem  Values can be constants or math functions of variable   
   "charsetsize"   
   +++   
   +++rem  NUMBERS OR LETTERS (default = Numbers)   
   +++set default_alphanum=Numbers   
   +++   
   +++rem  USE CHARACTERS MORE THAN ONCE (default = No)   
   +++set default_repetition=No   
   +++   
   +++rem  LENGTH OF SECRET (default = 5 numbers or 13 letters)   
   +++set default_secretlength=charsetsize / 2   
   +++   
   +++rem  HOW MANY CHARACTERS TO PICK FROM (default = 8 numbers or 20   
   letters)   
   +++set default_palletlength=charsetsize * 8 / 10   
   +++   
   +++rem  these are for Donald Knute's game version   
   +++set default_alphanum=Numbers   
   +++set default_repetition=Yes   
   +++set default_secretlength=4   
   +++set default_palletlength=6   
   +++   
   +++rem  ****************** DISPLAY OPTION ******************   
   +++   
   +++rem  mark every Nth line with _ to make it easier to read across rows   
   +++set mark_alternate_lines=3   
   +++   
   +++rem  *****************************************************   
   +++   
   +++rem  clear options   
   +++rem  once options are chosen, they become defaults for new games   
   +++set "alphanum="   
   +++set "repetition="   
   +++set "secretlength="   
   +++set "maxsecret="   
   +++set "palletlength="   
   +++   
   +++set /a completed_games=0   
   +++set /a completed_guesses=0   
   +++set /a aborted_games=0   
   +++set /a aborted_guesses=0   
   +++   
   +++:begin   
   +++echo;   
   +++call :randomize   
   +++call :get_options   
   +++call :create_secret   
   +++set "guess_overbar="   
   +++for /l %%a in (1,1,%secretlength%) do call set   
   "guess_overbar=%%guess_overbar%%_"   
   +++   
   +++set /a guesscount=0   
   +++:get_guess   
   +++cls   
   +++call :show_guess_history   
   +++set "guess=_"   
   +++echo Guess %secretlength% %character_type% between %pallet:~0,1% and   
   %pallet:~-1,1% (%promptsuffix%)   
   +++echo; %guess_overbar%   
   +++set /p "guess=|"   
   +++if not "%guess:"=#%"=="%guess:"=$%" goto :get_guess   
   +++if not "%guess: =#%"=="%guess: =$%" goto :get_guess   
   +++if not "%guess%"=="_" goto :keepplaying   
   +++     set "alt_option=_"   
   +++     call :average_score   
   +++     set /p "alt_option=Enter Q to Quit or N for a New game: "   
   +++     echo;   
   +++     if /i "%alt_option:"=#%"=="Q" (   
   +++          echo Secret = %secret%   
   +++          echo;   
   +++          pause   
   +++          title Command Prompt   
   +++          if "%~F0"=="%0" (exit) else (goto :eof)   
   +++     )   
   +++     if /i "%alt_option:"=#%"=="N" (   
   +++          echo Secret = %secret%   
   +++          set /a aborted_games += 1   
   +++          set /a aborted_guesses += guesscount   
   +++          echo;   
   +++          pause   
   +++          goto :begin   
   +++     )   
   +++     goto :get_guess   
   +++:keepplaying   
   +++rem  check length of guess   
   +++set /a p = secretlength   
   +++call set "c=%%guess:~%p%,1%%"   
   +++if not "%c%"=="" goto :get_guess   
   +++set /a p = secretlength - 1   
   +++call set "c=%%guess:~%p%,1%%"   
   +++if "%c%"=="" goto :get_guess   
   +++rem  check validity of chars in guess (delims is case sensitive so   
   convert to upper first)   
   +++if /i %alphanum%==L call :toupper guess   
   +++for /f "tokens=* delims=%pallet%" %%a in ("%guess%.") do if not   
   "%%a"=="." goto :get_guess   
   +++set /a guesscount += 1   
   +++rem  guess is now certified to be a valid string   
   +++   
   +++rem  score guess   
   +++rem  first search for matches in the correct positions   
   +++rem  and mark them in temp variables so they are counted separately   
   +++rem  which is less efficient than a single loop but necessary to   
   score when repetition is allowed   
   +++set "XXXX="   
   +++set "OOOO="   
   +++if %secretlength% gtr 10 echo Checking...This will take a minute.   
   +++set "secret_X_marks="   
   +++set "guess_X_marks="   
   +++set /a p=0   
   +++:next_exact_match   
   +++     call set char_secret=%%secret:~%p%,1%%   
   +++     call set char_guess=%%guess:~%p%,1%%   
   +++     if /i %char_secret%==%char_guess% (   
   +++          set "XXXX=%XXXX%X "   
   +++          set "secret_X_marks=%secret_X_marks%_"   
   +++          set "guess_X_marks=%guess_X_marks%-"   
   +++     ) else (   
   +++          set "secret_X_marks=%secret_X_marks%%char_secret%"   
   +++          set "guess_X_marks=%guess_X_marks%%char_guess%"   
   +++     )   
   +++     set /a p += 1   
   +++if %p% lss %secretlength% goto :next_exact_match   
   +++   
   +++rem  search for matches in the wrong positions   
   +++rem  chars in "X_marks" vars are compared because they have _ or -   
   where exact matches are   
   +++set /a p_s=0   
   +++:next_char_secret   
   +++     set "new_match="   
   +++     set "guess_O_marks="   
   +++     set /a p_g=0   
   +++     :next_char_guess   
   +++          call set "char_secret=%%secret_X_marks:~%p_s%,1%%   
   +++          call set "char_guess=%%guess_X_marks:~%p_g%,1%%   
   +++          if /i %char_secret%==%char_guess% (   
   +++               if not defined new_match (   
   +++                    rem  chars equal but secret char didn't match   
   earlier guess char   
   +++                    set "new_match=o "   
   +++                    set "guess_O_marks=%guess_O_marks%-"   
   +++               ) else (   
   +++                    set "guess_O_marks=%guess_O_marks%%char_guess%"   
   +++               )   
   +++          ) else (   
   +++               set "guess_O_marks=%guess_O_marks%%char_guess%"   
   +++          )   
   +++          set /a p_g += 1   
   +++     if %p_g% lss %secretlength% goto :next_char_guess   
   +++     set "OOOO=%OOOO%%new_match%"   
   +++     set /a p_s += 1   
   +++     set "guess_X_marks=%guess_O_marks%"   
   +++if %p_s% lss %secretlength% goto :next_char_secret   
   +++   
   +++rem  space characters apart   
   +++for %%a in (0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S   
   T U V W X Y Z) do call set "guess=%%guess:%%a=%%a %%"   
   +++set /a mark_alternate_lines += 0   
   +++if %mark_alternate_lines%0 leq 0 set /a mark_alternate_lines = 1000   
   +++set /a markline = guesscount %% mark_alternate_lines   
   +++if %markline%==0 (set "spacer=_") else (set "spacer= ")   
   +++set "guess_history[%guesscount%]= %spacer% %guess%%spacer%   
   %XXXX%%OOOO%"   
   +++   
   +++rem  check score bars   
   +++if     defined OOOO goto :get_guess   
   +++if not defined XXXX goto :get_guess   
   +++set /a p = secretlength * 2   
   +++set "XXXX_test=%XXXX%_"   
      
   [continued in next message]   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca