Skip to content

Instantly share code, notes, and snippets.

@Porges
Created November 11, 2013 19:25
Show Gist options
  • Save Porges/7418817 to your computer and use it in GitHub Desktop.
Save Porges/7418817 to your computer and use it in GitHub Desktop.
A transcription of a BASIC program into C#. This is buggy (wins happen when they shouldn't) but I'm not sure if it's a typo or an error in the printed version (or a misunderstanding of a BASIC construct). Original: http://www.atariarchives.org/bigcomputergames/showpage.php?page=43
using System;
// Mu-Torere
// in terrible C#
// transcribed from: http://www.atariarchives.org/bigcomputergames/showpage.php?page=43 (and following)
class MuTorere
{
static int[] H;
static int[] A;
static int FnP(int x)
{
//return x - 9*(-1*Convert.ToInt32(x > 9)); // original - seems to be buggy
return x - 9*(1*Convert.ToInt32(x > 9)); // modified
}
static int FnA(int x)
{
return A[FnP(x)];
}
static Random rnd = new Random();
static int I;
static int X;
static int Y;
static int ZR;
static int D;
static int P;
static int Q;
static int SW;
static int FnR(int x)
{
return (int)(1 + x*rnd.NextDouble());
}
static void Main()
{
goto L1030;
// *** Player's Move ***
L100:
Console.WriteLine();
Console.WriteLine();
Console.Write("Your move: ");
l110:
X = VAL(Console.ReadKey(true));
Console.Write("{0},", X);
Y = VAL(Console.ReadKey(true));
Console.WriteLine(Y);
if (A[X] != 1 || (int)A.GetValue(Y) != 0)
goto l170;
if (X == 0 || Y == 0 || Math.Abs(X - Y) == 1 || Math.Abs(X - Y) == 8)
goto l180;
l170:
Console.WriteLine("Invalid move. Try again: ");
goto l110;
l180:
A[X] = 0; A[Y] = 1;
ZR = Y;
L1250();
P = 1;
L770();
P = -1;
L290();
if (ZR == Y)
L550();
A[X] = 0;
A[Y] = -1;
L250:
Console.Clear();
Console.Write(" My move: {0},{1}",X,Y);
L1150();
L950();
L770();
L1250();
goto L100;
L1030:
H = new int[3];
A = new int[10];
Console.Clear();
Console.SetCursorPosition(16, Console.CursorTop);
Console.WriteLine("MU-TORERE");
Console.WriteLine();
Console.WriteLine(" The object of the game is to make it");
Console.WriteLine("impossible for your opponent to move.");
Console.WriteLine();
Console.WriteLine(" There are 3 types of legal moves:");
Console.WriteLine();
Console.WriteLine(" 1. Sideways to the next adjacent");
Console.WriteLine(" square (1 and 9 are adjacent)");
Console.WriteLine(" 2. To 0 if it is empty");
Console.WriteLine(" 3. From 0 to any unoccupied number");
Console.WriteLine();
Console.WriteLine(" You and the computer take");
Console.WriteLine("alternating moves until the game ends.");
Console.WriteLine();
Console.WriteLine(" To move, just press the number you");
Console.WriteLine("moving from and the number you are");
Console.WriteLine("moving to.");
Console.WriteLine();
Console.WriteLine(" You play 'X' and the computer");
Console.WriteLine("plays 'O'.");
Console.WriteLine(" Press any key to begin.");
Console.ReadKey(true);
Console.Clear();
for (I = 1; I <= 4; ++I) { A[I] = 1; A[I+5] = -1; }
A[0] = 0; A[5] = 0;
L1150();
L950();
L1250();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Do you want to go first (Y or N) ?");
if (Console.ReadKey(true).Key != ConsoleKey.N)
goto L100;
P = -1;
if (FnR(3) < 3)
{
A[6] = 0;
A[5] = -1;
X = 6;
Y = 5;
goto L250;
}
X = FnR(4) + 5;
Y = 0;
A[X] = 0;
A[0] = -1;
goto L250;
}
static void L950()
{
H[1] = -1;
Console.WriteLine();
for (I = 1; I <= 9; ++I)
{
Console.SetCursorPosition(4*I - 3, Console.CursorTop);
L980();
}
}
static void L770()
{
if (A[0] == 0 || A[0] == -P) return;
H[0] = H[1];
L880();
if (Q != 0) return;
H[0] = H[2];
L880();
if (Q != 0) return;
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.Beep();
Console.Beep();
Console.Beep();
if (P == 1) Console.WriteLine("YOU WIN!");
if (P == -1) Console.WriteLine("THE COMPUTER WINS!");
Console.WriteLine();
Console.WriteLine("Care to play again (Y or N) ?");
if (Console.ReadKey(true).Key == ConsoleKey.N)
{
Console.Clear();
Environment.Exit(0);
}
Main();
}
static void L880()
{
Q = 0;
if (A[0] == -P)
{
Q = 1;
return;
}
if (H[0] > 1)
{
if (A[H[0] - 1] == -P)
{
Q = 1;
return;
}
}
if (H[0] < 8)
{
if (A[H[0] + 1] == -P)
{
Q = 1;
return;
}
}
if (H[0] == 1)
{
if (A[9] == -P)
{
Q = 1;
return;
}
}
if (H[0] == 9)
{
if (A[1] == -P)
{
Q = 1;
return;
}
}
}
static void L550()
{
L290(true);
}
// *** Computer's Move ***
static void L290(bool l550 = false)
{
if (l550) goto L550;
if (H[1] != 0)
{
H[0] = H[1];
L660();
}
if (SW == 1)
{
SW = 0;
return;
}
if (H[2] != 0)
{
H[0] = H[2];
L660();
}
switch (A[0])
{
case -1:
goto L590;
case 0:
goto L340;
case 1:
goto L510;
}
// *** if 0 Square is Empty
L340:
if (FnA(H[2] + 8) != -1 || FnA(H[2]+1) != -1)
{
goto L370;
}
if (FnA(H[2] + 7) != -1)
{
X = FnP(H[2] + 8);
Y = 0;
return;
}
if (FnA(H[2] + 2) != -1)
{
X = FnP(H[2] + 1);
Y = 0;
return;
}
L370:
H[2] = H[0];
if (FnA(H[0] + 7) == 1 && FnA(H[0] + 8) == -1 &&
FnA(H[0] + 1) == 1)
{
X = FnP(H[0] + 8);
Y = -X;
}
L380:
if (FnA(H[0] + 2) == 1 && FnA(H[0] + 3) == 1 && Y == -X)
{
goto L430;
}
if (Y == -X)
{
Y = 0;
return;
}
if (FnA(H[0] + 2) == 1 && FnA(H[0] + 1) == -1 && FnA(H[0] + 8) == 1)
{
X = FnP(H[0] + 1);
Y = -X;
}
if (FnA(H[0] + 7) == 1 && FnA(H[0] + 6) == 1 && Y == -X)
{
goto L430;
}
if (Y == -X)
{
Y = 0;
return;
}
L430:
I = 0;
L440:
I = I + 1;
if (I > 9)
I = 1;
if (A[I] != -1 || FnR(4) < 3)
{
goto L440;
}
if (FnA(I + 8) == 0 && FnR(4) < 3)
{
X = I;
Y = FnP(I + 8);
return;
}
if (FnA(I + 1) == 0 && FnR(4) < 3)
{
X = I;
Y = FnP(I + 1);
return;
}
if (Y != -I && FnR(4) < 3)
{
X = I;
Y = 0;
return;
}
L490:
goto L440;
// *** If 0 Square Contains an X
L510:
H[0] = H[1];
L690();
if (SW == 1)
{
SW = 0;
return;
}
L520:
H[0] = H[2];
L690();
if (SW == 1)
{
SW = 0;
return;
}
L530:
if (FnA(H[0] + 1) == -1 && FnR(4) < 3)
{
X = FnP(H[0] + 1);
Y = H[0];
return;
}
L540:
if (FnA(H[0] + 8) == -1 && FnR(4) < 3)
{
X = FnP(H[0] + 8);
Y = H[0];
return;
}
L550:
if (A[0] == -1 && FnR(4) < 3)
{
X = 0;
Y = H[FnR(2)];
return;
}
L560:
if (H[0] == H[2])
{
H[0] = H[1];
goto L530;
}
L570:
H[0] = H[2];
goto L530;
// *** IF 0 Square Contains an O
L590:
H[0] = H[1];
L720();
if (SW == 1)
{
SW = 0;
return;
}
L600:
H[0] = H[2];
L720();
if (SW == 1)
{
SW = 0;
return;
}
L610:
H[0] = H[1];
L750();
if (SW == 1)
{
SW = 0;
return;
}
L620:
H[0] = H[2];
L750();
if (SW == 1)
{
SW = 0;
return;
}
L630:
H[0] = H[1];
L690();
if (SW == 1)
{
SW = 0;
return;
}
L640:
H[0] = H[2];
L690();
if (SW == 1)
{
SW = 0;
return;
}
goto L530;
}
static void L660()
{
if (FnA(H[0] + 8) == 1 && FnA(H[0] + 1) == -1 && FnA(H[0] + 2) == -1)
{
X = FnP(H[0] + 1);
Y = H[0];
SW = 1;
return;
}
if (FnA(H[0] + 1) == 1 && FnA(H[0] + 8) == -1 && FnA(H[0] + 7) == -1)
{
X = FnP(H[0] + 8);
Y = H[0];
SW = 1;
return;
}
return;
}
static void L690()
{
if (FnA(H[0] + 1) == -1 && FnA(H[0] + 2) == -1)
{
X = FnP(H[0] + 1);
Y = H[0];
SW = 1;
}
else if (FnA(H[0] + 8) == -1 && FnA(H[0] + 7) == -1)
{
X = FnP(H[0] + 8);
Y = H[0];
SW = 1;
}
}
static void L720()
{
if (FnA(H[0] + 8) == -1 && FnA(H[0] + 1) == -1 && FnA(H[0] + 2) == 0)
{
X = FnP(H[0] + 1);
Y = FnP(H[0] + 2);
SW = 1;
}
else if (FnA(H[0] + 1) == -1 && FnA(H[0] + 8) == -1 && FnA(H[0] + 7) == 0)
{
X = FnP(H[0] + 8);
Y = FnP(H[0] + 7);
SW = 1;
}
}
static void L750()
{
if (FnA(H[0] + 8) == 1 && FnA(H[0] + 1) == 1)
{
X = 0;
Y = H[0];
SW = 1;
return;
}
return;
}
static void L1250()
{
D = 1;
for (I = 0; I <= 9; ++I)
{
if (A[I] == 0)
{
H[D] = I;
D = D + 1;
}
}
}
static int VAL(ConsoleKeyInfo input)
{
if (input.Key >= ConsoleKey.D0 &&
input.Key <= ConsoleKey.D9)
return input.Key - ConsoleKey.D0;
return 0;
}
static void L1150()
{
Console.SetCursorPosition(17, Console.CursorTop); // bug: was 173
Console.WriteLine("0");
Console.SetCursorPosition(17, Console.CursorTop);
I = 0;
L980();
Console.WriteLine();
Console.WriteLine();
for (I = 1; I <= 9; ++I) { Console.Write(" {0} ",I); Console.Write(" "); }
}
static void L980()
{
if (A[I] == 1) Console.Write("X");
if (A[I] == -1) Console.Write("O");
if (A[I] == 0) Console.Write("I");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment