From ccdfbdbaacb4f2e0d8e84ffa057258620058aa39 Mon Sep 17 00:00:00 2001 From: def Date: Sat, 27 Jun 2020 13:16:53 +0200 Subject: [PATCH] Remove defunct snake/tron scripts (fixes #24) --- servers/scripts/snake.py | 126 ------------------------ servers/scripts/snake.sh | 3 - servers/scripts/tron.py | 202 --------------------------------------- servers/scripts/tron.sh | 3 - 4 files changed, 334 deletions(-) delete mode 100755 servers/scripts/snake.py delete mode 100755 servers/scripts/snake.sh delete mode 100755 servers/scripts/tron.py delete mode 100755 servers/scripts/tron.sh diff --git a/servers/scripts/snake.py b/servers/scripts/snake.py deleted file mode 100755 index c7fab6f..0000000 --- a/servers/scripts/snake.py +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/python2 -u -# coding: utf8 -import random -import time -import sys -import threading -import big -import re - -rows = 16 -cols = 16 - -lastinput = "left" -running = True - -idP1 = sys.argv[1] -nameP1 = "Player " + idP1 - -def opposite(x,y): - if (x.startswith("left") and y.startswith("right")) or (x.startswith("right") and y.startswith("left")) or (x.startswith("down") and y.startswith("up")) or (x.startswith("up") and y.startswith("down")): - return True - return False - -def escape(x): - return re.sub(r'([\"])', r'\\\1', x) - -def input(): - global lastinput, idP1, nameP1, running - while running: - inp = sys.stdin.readline().strip().split("\t") - if len(inp) == 3: - if inp[1] == idP1: - nameP1 = escape(inp[2]) - else: - if inp[0] == idP1: - if not opposite(inp[1], lastinput): - lastinput = inp[1] - -def broadcast(s): - print("broadcast \"" + s + "\"") - sys.stdout.flush() - -threading.Thread(target=input).start() - -air = "▢" -snake = "▩" -food = "■" -br = "\\n" - -try: - broadcast(big.big("Snake")) - time.sleep(2) - print("status") - broadcast(big.big("by done")) - time.sleep(2) - broadcast(nameP1 + " is playing!") - time.sleep(4) - while running: - board = [[0 for x in range(cols)] for x in range(rows)] - headx = cols/2 - heady = rows/2 - board[heady][headx] = 1 - board[cols/2][rows/4] = -1 - score = 0 - gameover = False - sleeptime = 0.2 - - while not gameover: - display = "" - for row in range(rows): - for col in range(cols): - if board[row][col] == 0: - display += air - elif board[row][col] > 0: - display += snake - elif board[row][col] < 0: - display += food - display += br - display = display[:-2] - broadcast(display) - - time.sleep(sleeptime) - - newHeadx = headx - newHeady = heady - - if lastinput.startswith("up"): - newHeady -= 1 - elif lastinput.startswith("down"): - newHeady += 1 - elif lastinput.startswith("left"): - newHeadx -= 1 - else: - newHeadx += 1 - - if newHeady < 0 or newHeady >= rows or newHeadx < 0 or newHeadx >= cols or board[newHeady][newHeadx] > 0: - gameover = True - break - - if board[newHeady][newHeadx] < 0: - score += 1 - sleeptime *= 0.98 - board[newHeady][newHeadx] = 1 + board[heady][headx] - found = False - while not found: - y = random.randint(0, rows-1) - x = random.randint(0, cols-1) - if board[y][x] == 0: - board[y][x] = -1 - found = True - headx = newHeadx - heady = newHeady - else: - board[newHeady][newHeadx] = 1 + board[heady][headx] - for x in range(rows): - for y in range(cols): - if board[x][y] > 0: - board[x][y] -= 1 - - headx = newHeadx - heady = newHeady - - broadcast(big.big("Score: " + str(score))) - time.sleep(2) -except KeyboardInterrupt: - running = False diff --git a/servers/scripts/snake.sh b/servers/scripts/snake.sh deleted file mode 100755 index df3219b..0000000 --- a/servers/scripts/snake.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env zsh -SERVER=$1 -inotail -f servers/$SERVER.log | grep --line-buffered "^\[.*\]\[server\]: ClientID=.* rcon='.*'$\|^\[.*\]\[Server\]: id=.*" | sed -u -e "s/.*id=\(.*\) .* name='\(.*\)' score=.*/name\t\1\t\2/" | sed -u -e "s/.*ClientID=\(.*\) rcon='\(.*\)'$/\1\t\2/" | scripts/snake.py $2 > servers/$SERVER.fifo diff --git a/servers/scripts/tron.py b/servers/scripts/tron.py deleted file mode 100755 index 520c257..0000000 --- a/servers/scripts/tron.py +++ /dev/null @@ -1,202 +0,0 @@ -#!/usr/bin/python2 -u -# coding: utf8 -import random -import time -import sys -import threading -import big -import re - -rows = 17 -cols = 17 - -idP1 = sys.argv[1] -idP2 = sys.argv[2] - -nameP1 = "Player " + idP1 -nameP2 = "Player " + idP2 - -lastinputP1 = "right" -lastinputP2 = "left" - -def opposite(x,y): - if (x.startswith("left") and y.startswith("right")) or (x.startswith("right") and y.startswith("left")) or (x.startswith("down") and y.startswith("up")) or (x.startswith("up") and y.startswith("down")): - return True - return False - -def escape(x): - return re.sub(r'([\"])', r'\\\1', x) - -running = True - -def input(): - global lastinputP1, lastinputP2, nameP1, nameP2, running - while running: - inp = sys.stdin.readline().strip().split("\t") - if len(inp) == 3: - if inp[1] == idP1: - nameP1 = escape(inp[2]) - elif inp[1] == idP2: - nameP2 = escape(inp[2]) - else: - if inp[0] == idP1: - if not opposite(inp[1], lastinputP1): - lastinputP1 = inp[1] - elif inp[0] == idP2: - if not opposite(inp[1], lastinputP2): - lastinputP2 = inp[1] - -def broadcast(s): - print("broadcast \"" + s + "\"") - sys.stdout.flush() - -threading.Thread(target=input).start() - -air = "▢" -snakeP1 = "▩" -snakeP2 = "▦" -food = "■" -br = "\\n" - -try: - broadcast(big.big("Tron")) - time.sleep(2) - print("status") - broadcast(big.big("by DoNe")) - time.sleep(2) - broadcast(nameP2 + " (▩) vs " + nameP1 + " (▦)!") - time.sleep(4) - while running: - board = [[0 for x in range(cols)] for x in range(rows)] - - headxP1 = cols/2+4 - headyP1 = rows/2 - board[headyP1][headxP1] = 3 - board[headyP1][headxP1-1] = 2 - board[headyP1][headxP1-2] = 1 - scoreP1 = 0 - - headxP2 = cols/2-4 - headyP2 = rows/2 - board[headyP2][headxP2] = -3 - board[headyP2][headxP2+1] = -2 - board[headyP2][headxP2+2] = -1 - scoreP2 = 0 - - board[cols/2][rows/2] = 500 - gameover = False - sleeptime = 0.2 - - lastinputP1 = "right" - lastinputP2 = "left" - - while not gameover: - display = "" - for row in range(rows): - for col in range(cols): - if board[row][col] == 0: - display += air - elif board[row][col] > 0 and board[row][col] < 500: - display += snakeP1 - elif board[row][col] < 0: - display += snakeP2 - elif board[row][col] == 500: - display += food - display += br - display = display[:-2] - broadcast(display) - - time.sleep(sleeptime) - - newHeadxP1 = headxP1 - newHeadyP1 = headyP1 - newHeadxP2 = headxP2 - newHeadyP2 = headyP2 - - if lastinputP1.startswith("up"): - newHeadyP1 -= 1 - elif lastinputP1.startswith("down"): - newHeadyP1 += 1 - elif lastinputP1.startswith("left"): - newHeadxP1 -= 1 - else: - newHeadxP1 += 1 - - if lastinputP2.startswith("up"): - newHeadyP2 -= 1 - elif lastinputP2.startswith("down"): - newHeadyP2 += 1 - elif lastinputP2.startswith("left"): - newHeadxP2 -= 1 - else: - newHeadxP2 += 1 - - failP1 = False - failP2 = False - - if newHeadyP1 < 0 or newHeadyP1 >= rows or newHeadxP1 < 0 or newHeadxP1 >= cols or (board[newHeadyP1][newHeadxP1] > 0 and board[newHeadyP1][newHeadxP1] < 500) or board[newHeadyP1][newHeadxP1] < 0: - failP1 = True - - if newHeadyP2 < 0 or newHeadyP2 >= rows or newHeadxP2 < 0 or newHeadxP2 >= cols or (board[newHeadyP2][newHeadxP2] > 0 and board[newHeadyP2][newHeadxP2] < 500) or board[newHeadyP2][newHeadxP2] < 0: - failP2 = True - if newHeadxP1 == newHeadxP2 and newHeadyP1 == newHeadyP2: - failP1 = True - failP2 = True - - if failP1 or failP2: - gameover = True - break - - if board[newHeadyP1][newHeadxP1] == 500 and board[newHeadyP2][newHeadxP2] != 500: - board[newHeadyP1][newHeadxP1] = 1 + board[headyP1][headxP1] - found = False - while not found: - y = random.randint(0, rows-1) - x = random.randint(0, cols-1) - if board[y][x] == 0: - board[y][x] = 500 - found = True - headxP1 = newHeadxP1 - headyP1 = newHeadyP1 - else: - board[newHeadyP1][newHeadxP1] = 1 + board[headyP1][headxP1] - for x in range(rows): - for y in range(cols): - if board[x][y] > 0 and board[x][y] < 500: - board[x][y] -= 1 - headxP1 = newHeadxP1 - headyP1 = newHeadyP1 - - if board[newHeadyP2][newHeadxP2] == 500 and board[newHeadyP1][newHeadxP1] != 500: - board[newHeadyP2][newHeadxP2] = -1 + board[headyP2][headxP2] - found = False - while not found: - y = random.randint(0, rows-1) - x = random.randint(0, cols-1) - if board[y][x] == 0: - board[y][x] = 500 - found = True - headxP2 = newHeadxP2 - headyP2 = newHeadyP2 - else: - board[newHeadyP2][newHeadxP2] = -1 + board[headyP2][headxP2] - for x in range(rows): - for y in range(cols): - if board[x][y] < 0: - board[x][y] += 1 - headxP2 = newHeadxP2 - headyP2 = newHeadyP2 - - if failP1 or failP2: - gameover = True - break - - if failP1 and failP2: - broadcast("Draw!") - elif failP1: - broadcast(nameP2 + " (▦) wins!") - elif failP2: - broadcast(nameP1 + " (▩) wins!") - time.sleep(2) -except KeyboardInterrupt: - running = False diff --git a/servers/scripts/tron.sh b/servers/scripts/tron.sh deleted file mode 100755 index eece5f6..0000000 --- a/servers/scripts/tron.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env zsh -SERVER=$1 -inotail -f servers/$SERVER.log | grep --line-buffered "^\[.*\]\[server\]: ClientID=.* rcon='.*'$\|^\[.*\]\[Server\]: id=.*" | sed -u -e "s/.*id=\(.*\) .* name='\(.*\)' score=.*/name\t\1\t\2/" | sed -u -e "s/.*ClientID=\(.*\) rcon='\(.*\)'$/\1\t\2/" | scripts/tron.py $2 $3 > servers/$SERVER.fifo