Permalink
Browse files

Started PRIVMSG detection, joins #botwar on start up

  • Loading branch information...
1 parent 8eb5e30 commit 7f55922fb46f2dd6b19aaf95ab508e9d70f6ff5f @SirCmpwn committed Jan 4, 2013
Showing with 90 additions and 10 deletions.
  1. +5 −0 .gitignore
  2. +23 −1 irc-bot.bf
  3. BIN netfuck.exe
  4. +62 −9 netfuck/Program.cs
View
@@ -0,0 +1,5 @@
+bin/
+obj/
+*.suo
+*.user
+TestResults/
View
@@ -85,4 +85,26 @@ Send NICK and USER
\n > .
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end of "NICK bfbot\r\nUSER bfbot a :bfbot\r\n"
-+[,]
+Loop until we get a PRIVMSG with a channel to join
+>
+cell #0: working cell for iteration and such
+cell #1 stdin (pointer currently points here)
+[
+ PRIVMSG comes in like this: ":user PRIVMSG bfbot :message"
+ >+[,<[-]++++++++++[>---<-]>--] Loop until a space (32) is read
+ Check for P (80)
+ , < ++++++++++ [ > -------- <- ] [- zero working cell to 1]+ >
+ [ if (input != 'P')
+ [ , ---------- ] Read to \n (10); also zeroes cell
+ <->
+ ]<[ if (input == 'P')>
+ TEMPORARY DEBUG CODE
+ (74 79 73 78 32 35 98 111 116 119 97 114 13 10)
+ ++++++++++
+ [>+++++++>+++++++>+++++++>+++++++>+++>+++>+++++++++>+++++++++++>+++++++++++>+++++++++++>+++++++++>+++++++++++>+>+<<<<<<<<<<<<<<-]
+ >++++.>+++++++++.>+++.>++++++++.>++.>+++++.>++++++++.>+.>++++++.>+++++++++.>+++++++.>++++.>+++.>.
+ [,[-]+]
+ END DEBUG CODE
+ ]
+ <[-]+ reset working cell to 1; loop
+]
View
Binary file not shown.
View
@@ -30,9 +30,37 @@ private static void Main(string[] args)
var memory = new byte[ushort.MaxValue + 1];
ushort pointer = 0;
int codeIndex = 0;
+ bool inDebugger = false;
while (codeIndex < code.Length)
{
- switch (code[codeIndex++])
+ if (inDebugger)
+ {
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine("Current instruction: " + code[codeIndex] + " (source index " + codeIndex + ")");
+ Console.WriteLine("Memory pointer: " + pointer);
+ Console.Write("Memory dump: ");
+ for (ushort i = (ushort)(pointer - 4); i < pointer + 5; i++)
+ {
+ if (pointer == i)
+ Console.Write("[" + memory[i] + "]");
+ else
+ Console.Write(memory[i]);
+ }
+ var command = "";
+ while (command != "continue")
+ {
+ Console.Write(">");
+ command = Console.ReadLine();
+ if (command.StartsWith("cell "))
+ Console.WriteLine(memory[int.Parse(command.Substring(5))]);
+ else if (command == "step")
+ break;
+ else if (command == "continue")
+ inDebugger = false;
+ }
+ Console.ResetColor();
+ }
+ switch (code[codeIndex])
{
case '>':
pointer++;
@@ -57,26 +85,51 @@ private static void Main(string[] args)
case '[':
if (memory[pointer] == 0)
{
- codeIndex = code.IndexOf(']', codeIndex);
- if (codeIndex == -1)
+ int depth = 0;
+ while (depth >= 0)
{
- Console.WriteLine("Error: Hanging '['");
- return;
+ codeIndex++;
+ if (code[codeIndex] == '[') depth++;
+ if (code[codeIndex] == ']') depth--;
+ if (codeIndex >= code.Length)
+ {
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine("ERROR: Hanging '['");
+ Console.ResetColor();
+ return;
+ }
}
}
break;
case ']':
if (memory[pointer] != 0)
{
- codeIndex = code.Remove(codeIndex).LastIndexOf('[');
- if (codeIndex == -1)
+ int depth = 0;
+ while (depth >= 0)
{
- Console.WriteLine("Error: Hanging ']'");
- return;
+ codeIndex--;
+ if (code[codeIndex] == ']') depth++;
+ if (code[codeIndex] == '[') depth--;
+ if (codeIndex < 0)
+ {
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine("ERROR: Hanging ']'");
+ Console.ResetColor();
+ return;
+ }
}
}
break;
+ case '@':
+ if (debug)
+ {
+ inDebugger = true;
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine("Breakpoint hit, entering debug mode.");
+ }
+ break;
}
+ codeIndex++;
}
}

0 comments on commit 7f55922

Please sign in to comment.