free software resistance

 the cost of computing freedom is eternal vigilance

### trigame.py *original date:* feb 2011 *orginally posted:* sep 2024 i wrote this on a bus on paper, with basic before i learned python. it definitely did not work without some heavy editing- this is the port to python. this program plays the triangular game with golf tees for you, then tells you how it won: ``` import curses import time import os import random co = 0 moves = "" def loop(one): global co, moves while not co: ten(one) def ten(one): global co, moves wall = 0 curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_WHITE) rd = curses.color_pair(1) wt = curses.color_pair(2) log = "" #IF l = 2 THEN #SOUND 1276, 1: SOUND 32767, 1: SOUND 1276, 1 #t = TIMER: DO: LOOP UNTIL TIMER > t + .5 OR TIMER < t #t = TIMER: DO: LOOP UNTIL TIMER > t + .5 OR TIMER < t #END IF #CLEAR #CLS b = [] for p in range(6): b += [u""] ja = [] for p in range(16): ja += [0] C2 = u"#" b[1] = u" " * 16 + u"O_" + C2 + u"_1" + u" " * 12 b[2] = u" " * 13 + u"O_" + C2 + u"_2 O_" + C2 + u"_3" + " " * 9 b[3] = u" " * 10 + u"O_" + C2 + u"_4 O_" + C2 + u"_5 O_" + C2 + u"_6" + u" " * 6 b[4] = u" " * 7 + u"O_" + C2 + u"_7 O_" + C2 + u"_8 O_" + C2 + u"_9 I_" + C2 + u"_0" + u" " * 3 b[5] = u" 1_" + C2 + u"_1 1_" + C2 + "_2 1_" + C2 + u"_3 1_" + C2 + u"_4 1_" + C2 + u"_5" ## remove random peg (leaving 14 pegs) to start ja[random.randint(1, 15)] = 1 while 1: #start jumploop lc = 0 one.addstr(0, 0, u"\n") one.refresh() for blp in range (1, 5 + 1): one.addstr(u"\n") one.addstr(u"\n") one.addstr(u" " * 5 + "\n") one.refresh() ln = u"" for lp in b[blp]: if lp == "#": lc = lc + 1 if ja[lc] == 0: one.addstr(" ", wt) #ln += u" " else: one.addstr(" ", rd) #ln += u" " elif lp == "O" or lp == "I": cl = 8 one.addstr(lp, rd) #ln += lp elif lp == "[" or lp == "]": cl = 1 one.addstr(lp, rd) #ln += lp else: cl = 7 one.addstr(lp, rd) #ln += lp one.addstr(" \n") #for p in range(1, 15 + 1): # lo = [(0,0),(4,18),(8,12),(2,4),(2,5),(2,6),(2,7),(2,8),(2,9),(2,10),(2,11),(2,12),(2,13),(2,14),(2,15),(2,16)][p] # if ja[p] == 0: # one.addstr(lo[0], lo[1], " ", gr) # else: # one.addstr(lo[0], lo[1], " ") one.refresh() try: bl = l except: bl = 0 l = (15 - ja[1] - ja[2] - ja[3] - ja[4] - ja[5] - ja[6] - ja[7] - ja[8] - ja[9] - ja[10] - ja[11] - ja[12] - ja[13] - ja[14] - ja[15]) one.addstr(0, 0, str(l) + " pegs left" + " " * 10 + "wall value: " + str(wall) + " " * 10 + "\n") one.refresh() #time.sleep(.005) #this (and [pegsleft]) probably shouldn't be part of the drawboard routine if l == bl: wall += 1 #choosemove: '(choosemove) #pick move(c) m = "01,02,04=01,03,06=02,04,07=02,05,09=03,05,08=" m += "03,06,10=04,02,01=04,07,11=04,05,06=04,08,13=" m += "05,08,12=05,09,14=06,03,01=06,05,04=06,09,13=" m += "06,10,15=07,04,02=07,08,09=08,05,03=08,09,10=" m += "09,08,07=09,05,02=10,06,03=10,09,08=11,07,04=" m += "11,12,13=12,13,14=12,08,05=13,12,11=13,14,15=" m += "13,08,04=13,09,06=14,09,05=14,13,12=15,14,13=15,10,06" nm = m.split("=")[random.randint(0, 35)] ae = int(nm.split(",")[0]) be = int(nm.split(",")[1]) ce = int(nm.split(",")[2]) #if (a) not empty and (b) not empty and (c) empty then if ja[ae] == 0 and ja[be] == 0 and ja[ce] == 1: log += nm + " " ## log move wall = 0 ## wall count only needed when progress Not being made ## remove (a) and (b) and fill (c) ja[ae] = 1 ; ja[be] = 1 ; ja[ce] = 0 ## else goto choosemove (not needed) lc = 0 one.addstr(0, 0, "") one.refresh() for blp in range (1, 5 + 1): one.addstr(u"") one.addstr(u"") one.addstr(u" " * 5) one.refresh() ln = "" for lp in b[blp]: if lp == "#": lc = lc + 1 if ja[lc] == 0: ln += u"#" else: ln += u" " elif lp == "O" or lp == "I": cl = 8 ln += lp elif lp == "[" or lp == "]": cl = 1 ln += lp else: cl = 7 ln += lp #one.addstr(ln + u"\n") one.refresh() bl = l l = (15 - ja[1] - ja[2] - ja[3] - ja[4] - ja[5] - ja[6] - ja[7] - ja[8] - ja[9] - ja[10] - ja[11] - ja[12] - ja[13] - ja[14] - ja[15]) one.addstr(1, 1, str(l) + u" pegs left" + u" " * 10 + u"wall value: " + str(wall) + " " * 10 + u"\n") one.refresh() time.sleep(.01) if l == bl: wall += 1 #if l == 8 and wall >= 400: if l == 1: one.addstr(u"HEY!!!!!!!\n") one.addstr(u"\n") moves = u"moves are: " + log one.addstr(u"moves are: " + log + u"\n") one.refresh() #os.system("lp 2> /dev/null ; mplayer /root/tgz/cgi/*.ogg") ## DO: ## FOR slp = 12 TO 1 STEP -1: SOUND slp * 4 + 500, .2: NEXT slp: ## FOR slp = 1 TO 12 STEP 1: SOUND slp * 4 + 500, .2: NEXT slp: ## LOOP one.getch() co = 1 return if wall >= 250: wall = 0 return try: curses.wrapper(loop) print moves except KeyboardInterrupt: print moves ``` license: 0-clause bsd ``` # 2011 mn # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ``` => https://freesoftwareresistance.neocities.org