[Add-on] Tic-Tac-Toe NPC. Moogra is mean.

Joined
Aug 21, 2009
Messages
1,149
Reaction score
599
Okay so, I made a bet with Moogra meanwhile playing Minesweeper. I lost with a score of 25 - 26. Which is sad because he just cheated somehow. :(

Anyhow, making up my word as a loser. I had to release anything to RaGEZONE. He knows I hate to release, so he is probably with a huge smiley in his face while eating tacos. (Yes, Moogra is Mexican).

Okay, so, on topic. This is the NPC I made for my lose :(.

Don't enjoy it.

PHP:
status = -1;
playerFlag = 0;
computerFlag = 0;
var playerColor;
var computerColor;

function start() {
    cm.sendYesNo("Hello #h #. I just lost a bet against Moogra. He punished me hard, so meanwhile my injuries are not yet sanitized... Wanna play tic tac toe with a brainless computer and gain a #b#t1002140##k?");
}

function action (mode, type, selection) {
    if (mode != 1) {
	    if (type == 1 && mode == 0) {
		    cm.sendNext("Coward.");
		}
		cm.dispose();
		return;
	}
	status++;
	if (status == 0) {
	    cm.sendSimple("What do you wants be?\r\n\r\n#b#L0#First player.\r\n#L1#Second player.");
	} else if (status == 1) {
	    playerColor = selection == 0 ? 3991040 : 3991049;
		computerColor = selection == 0 ? 3991023 : 3991014;
		if (selection == 1) {
		    computerMoves();
		}
		play();
	} else {
	    if ((playerFlag & (1 << selection)) == (1 << selection) || (computerFlag & (1 << selection)) == (1 << selection) || selection < 0 || selection > 9) {
		    cm.sendNext("No cheaters allowed.");
			cm.dispose();
			return;
		}
		playerFlag |= 1 << selection;
		if (((playerFlag | computerFlag) ^ 511) == 0) {
		    tie();
			return;
		}
		for (var i = 0; i < 3; ) {
		    if (isWinner(playerFlag, i++)) {
			    win();
				return;
			}
		}
		computerMoves();
		for (var i = 0; i < 3; ) {
		    if (isWinner(computerFlag, i++)) {
			    lose();
				return;
			}
		}
	    play();
	}
}

function play() {
	cm.sendSimple(loadText(true));
}

function win() {
    if (cm.canHold(1002140)) {
	    cm.gainItem(1002140, 1);
		cm.sendNext(loadText(false) + "\r\n\r\nWoah! You made it! Congratulations! You have won a #b#t1002140##k.");
	} else {
	    cm.sendNext("Woah! You made it! Congratulations! But I'm sorry to tell you that I can give you the #b#t1002140##k because your Equip inventory seems to be full. Try again later.");
	}
	cm.dispose();
}

function isWinner(player, val) {
    return (player & (7 << (val * 3))) == 7 << (val * 3) || (player & (73 << val)) == (73 << val) || (((player & (1 << 4)) == 1 << 4) && (player & ((1 << 6) << (val * 2))) && ((player & (1 << 2) >> (val * 2))));
}

function lose() {
    cm.sendNext(loadText(false) + "\r\n\r\nIt's a shame that you have lost againts this computer. You should try again after you take your breakfast, you're probably just tired.");
	cm.dispose();
}

function computerMoves() {
	if (playerFlag == 0) {
	    var rand = Math.random() * 9 | 0;
	    computerFlag |= 1 << (rand + 1 & 1 == 1 ? rand : 4);
	} else {
	    if (computerFlag == 0) {
		    for (var i = 0; i < 4; i++) {
		        if (playerFlag & (2 << i) == 2 << i) {
				    computerFlag |= 1 << 4;
					return;
				}
			}
			var rand = Math.random() * 9 | 0;
			if (playerFlag == 1 << 4) {
	            computerFlag |= 1 << (rand + 1 & 1 == 1 ? rand : 0);
			} else {
			    if ((playerFlag & 1) << (rand + 1 & 1 == 1 ? rand : 4) != 1 << (rand + 1 & 1 == 1 ? rand : 4)) {
			        computerFlag |= 1 << (rand + 1 & 1 == 1 ? rand : 4);
				} else {
				    computerFlag |= 1 << 4;
				}
			}
		} else {
		    for (var i = 0; i < 9; i++) {
			    if (((computerFlag | playerFlag) & (1 << i)) != 0) {
				    continue;
				}
			    var nextMove = (computerFlag | (1 << i));
				for (var x = 0; x < 3; x++) {
				    if (isWinner(nextMove, x)) {
					    computerFlag |= 1 << i;
						return;
					}
				}
				var playerPossibleMove = (playerFlag | (1 << i));
				for (var x = 0; x < 3; x++) {
				    if (isWinner(playerPossibleMove, x)) {
					    computerFlag |= 1 << i;
						return;
					}
				}
			}
			for (var i = 0; i < 9; i++) {
			    if (((computerFlag | playerFlag) & (1 << i)) != 0) {
				    continue;
				}
			    computerFlag |= 1 << i;
				break;
			}
		}
	}
}

function loadText(sendSimple) {
    var text = (sendSimple ? "Pick your move." : "Match Result.") + "\r\n\r\n";
	for (var i = 0; i < 9; i++) {
		text += ((playerFlag & (1 << i)) == (1 << i) ? "#i" + playerColor + "#" : (computerFlag & (1 << i)) == (1 << i) ? "#i" + computerColor + "#" : ((sendSimple ? "#L" + i + "#" : "") + "___")) + "\t\t" + (((i + 1) % 3 == 0 ? "\r\n" : ""));
	}
	return text;
}

function tie() {
    cm.sendNext(loadText(false) + "\r\n\r\nOh, looks you you tied with the computer. You're really good player, but you need to try harder.");
	cm.dispose();
}

EDIT:

Images added upon request:

Begin
XxОsirisxX - [Add-on] Tic-Tac-Toe NPC. Moogra is mean. - RaGEZONE Forums

Playing
XxОsirisxX - [Add-on] Tic-Tac-Toe NPC. Moogra is mean. - RaGEZONE Forums

Tie
XxОsirisxX - [Add-on] Tic-Tac-Toe NPC. Moogra is mean. - RaGEZONE Forums

Lose
XxОsirisxX - [Add-on] Tic-Tac-Toe NPC. Moogra is mean. - RaGEZONE Forums
 
Last edited:
"Okay so, I made a bet with Moogra meanwhile playing Minesweeper. I lost with a score of 25 - 26. Which is sad because he just cheated somehow. :(

Anyhow, making up my word as a loser. I had to release anything to RaGEZONE. He knows I hate to release, so he is probably with a huge smiley in his face while eating tacos. (Yes, Moogra is Mexican).

Okay, so, on topic. This is the NPC I made for my lose :(.

Don't enjoy it."

somad!
 
Yeah, sadly I had to test it... It works. You have my word. The only thing that... is that the image position kinda sucks sometimes, but that's just esthetic... It works as intent.

Bingo NPC sounds like, a way easier task than this thought.

MSN, I'll explain the concept :p

As for the image factor, what's the issue with it? I can't tell since you didn't include screenshots. Not aligned properly? You forget the \t option :D:?
 
MSN, I'll explain the concept :p

As for the image factor, what's the issue with it? I can't tell since you didn't include screenshots. Not aligned properly? You forget the \t option :D:?

I do use \t. Thing is that the image changes size because of..

1. I switch between sendSimple and sendNext.

2. I I use ASCII, which change size, I should of use some invisible item I guess.

That's about it.
 
Release a Bingo NPC :O
JERK! :mad:

Well, when said jerk asked me to do this awhile ago, I obliged. I didn't complete it, because I'm very, very lazy, but I did leave pretty clear instructions for it. The only reason why I'm even posting this here is because everything is aligned more or less correctly and the item pictures make it look nice. If anyone wants to finish mine, I'm sure it'd be easier than making a whole new one.
Pretty badly done though, so don't flame (Osi) XD
PHP:
/**
 *
 * @author Sharky
 */
var status = 0, bet;
var AvailableCombinations = ["A1", "A2", "A3", "A4", "A5", "B1", "B2", "B3", "B4", "B5", "C1", "C2", "C3", "C4", "C5", "D1", "D2", "D3", "D4", "D5", "E1", "E2", "E3", "E4", "E5", "F1", "F2", "F3", "F4", "F5", "F6"];
var BingoCard = [];
var bingo = false;

function start() {
	cm.sendSimple("Hello! I'm hosting Bingo! What would you like to do?#b \r\n\t#L0#How do I play?#l \r\n\t#L1#I'd like to play!#l");
}

function action(mode, type, selection) {
	if(bingo) mode = 5;
	if(mode == 1) status++;
	else {
		if(mode == 5) {
			cm.sendOk("Congratulations! You got Bingo! You won " + (bet * 5) + " Mesos!");
			cm.gainMeso((bet * 5));
		} else if (mode == 6) {
			cm.sendOk("You've taken 20 turns! Looks like you didn't get Bingo fast enough and you lost your mesos!");
			cm.gainMeso(-bet);
		}
		cm.dispose();
		return;
	}
	if(status == 1) {
		if(selection == 0) {
			cm.sendOk("Haha, I see you are interested in playing Bingo! It's mainly for old people, but we'll try to have fun anyways XD \r\nThe goal of the game is to line up 5 Squishy Slime Shits in a row in under 20 turns. You can get a Squishy Slime **** on your Bingo Card if the Bingo Announcer calls out a combination you have on your card! If you can do this, you will receive some winnings! (Your bet x 5)");
			cm.dispose();
		} else if (selection == 1) {
			cm.sendSimple("How many mesos would you like to place on this game? If you win, you will receive 5x your bet!#b \r\n\t#L50000#50,000 Mesos!#l \r\n\t#L500000#500,000 Mesos!#l \r\n\t#L5000000000#5,000,000 Mesos!#l");
		}
	} else if (status == 2) {
		if(cm.getMeso() >= selection) {
			bet = selection;
			AssignBingoCard();
			DisplayBingoCardWithProgression();
		} else {
			cm.sendOk("You don't have enough mesos for this bet!");
			cm.dispose();
		}
	} else if (status > 2) {
		DisplayBingoCardWithProgression();
	}
}

function AssignBingoCard() {
	var SubCombs = [];
	for(var i = 0; i < AvailableCombinations.length; i++) {
		SubCombs.push(AvailableCombinations[i]);
	}
	for(var i = 0, r = -1; i < 25; i++) {
		r = Math.random() * SubCombs.length | 0;
		if(i != 12) {
			BingoCard.push(SubCombs[r]);
			SubCombs.splice(r, 1);
		} else {
			BingoCard.push("Spot");
		}
	}
}
	
function DisplayBingoCardWithProgression() {
	if(status < 23) {
		var chosenComb = Math.random() * AvailableCombinations.length | 0;
		var card = "#rBingo Announcer: \"" + AvailableCombinations[chosenComb] + "!!!\"";
		card += "\r\n\r\n#rYour Bingo Card!#k\r\n";
		for(var i = 0; i < BingoCard.length; i++) {
			if(BingoCard[i].equals(AvailableCombinations[chosenComb]))
				BingoCard[i] = "Spot";
			if(i % 5 == 0)
				card += "\r\n\r\n";
			else if (i != 0)
				card += "\t\t";
				if(!BingoCard[i].equals("Spot"))
					card += "\t"
			if(BingoCard[i].equals("Spot"))
				card += ("#i" + (4000545 + Math.random() * 3 | 0) + "#");
			else
				card += (BingoCard[i] + " ");
		}
		// Searches for Bingo
		/**
		 * Search for straight downs all across (BingoCard[0] to BingoCard[5]
		 * Search for straight acrosses all down the left side of the card (BingoCard[0], BingoCard[5], BingoCard[10], BingoCard[15], BingoCard[20], BingoCard[25])
		 * Search for diagonals at the corners (BingoCard[0], BingoCard[4], BingoCard[25], BingoCard[29])
		 */
		var count;
		if(BingoCard[0].equals("Spot")) {
			for(count = 1; count <= 5; count++) {
				if(!BingoCard[count].equals("Spot")) break; // Straight across
			}
			if(count < 5) {
				for(count = 1; count <= 5; count++) {
					if(!BingoCard[(count * 5)].equals("Spot")) break; // Stright down
				}
			}
			if(count < 5) {
				for(count = 1; count <= 5; count++) {
					if(!BingoCard[(count + 5)].equals("Spot")) break; // Diagonal
				}
			}
		}
		if(BingoCard[5].equals("Spot")) {
			// to-do
		}
		// End of Searching for Bingo
		if(count == 5) {
			bingo = true;
			card += "\r\n#e#rCongratulations! You got Bingo! Press Next to receive your prize!";
		}
		cm.sendNext(card);
		AvailableCombinations.splice(chosenComb, 1);
	} else
		action(6, 0, 0);
}
 
Last edited:
Back