Bots Home
|
Create an App
batt
Author:
funky_test
Description
Source Code
Launch Bot
Current Users
Created by:
Funky_Test
//Battleship by slavabo [cbslavabo[at]gmail.com] //Modified with prizes by rowan596 //Modified again as a bot by indshadow //Modified once again to remove some unnecessary things by funky_bean // var rls = 'v20130809'; //ReLeaSe version of game var tct = 0; //TipCounT: total tips received var act; //ACTivity (timestamp) var spc = String.fromCharCode(160); //SPaCe: non collapsible character // var bsz = 9; //BoardSiZe: cannot exceed 9 due to regex, brd[], ltr[] and fromLetter() var shp; //SHiPs: array of unhit ship coordinates; shp[0][0] is remaining (unhit) length of ship; shp[0][1+] is coordinates var brd; //BoaRD: status array of all board coordinates var ltr = ["A","B","C","D","E","F","G","H","I"]; //LeTteRs: used for numeric to alphabetic conversions var colors = { AliceBlue: '#F0F8FF', AntiqueWhite: '#FAEBD7', Aqua: '#00FFFF', Aquamarine: '#7FFFD4', Azure: '#F0FFFF', Beige: '#F5F5DC', Bisque: '#FFE4C4', Black: '#000000', BlanchedAlmond: '#FFEBCD', Blue: '#0000FF', BlueViolet: '#8A2BE2', Brown: '#A52A2A', BurlyWood: '#DEB887', CadetBlue: '#5F9EA0', Chartreuse: '#7FFF00', Chocolate: '#D2691E', Coral: '#FF7F50', CornflowerBlue: '#6495ED', Cornsilk: '#FFF8DC', Crimson: '#DC143C', Cyan: '#00FFFF', DarkBlue: '#00008B', DarkCyan: '#008B8B', DarkGoldenRod: '#B8860B', DarkGrey: '#A9A9A9', DarkGreen: '#006400', DarkKhaki: '#BDB76B', DarkMagenta: '#8B008B', DarkOliveGreen: '#556B2F', DarkOrange: '#FF8C00', DarkOrchid: '#9932CC', DarkRed: '#8B0000', DarkSalmon: '#E9967A', DarkSeaGreen: '#8FBC8F', DarkSlateBlue: '#483D8B', DarkSlateGrey: '#2F4F4F', DarkTurquoise: '#00CED1', DarkViolet: '#9400D3', DeepPink: '#FF1493', DeepSkyBlue: '#00BFFF', DimGrey: '#696969', DodgerBlue: '#1E90FF', FireBrick: '#B22222', FloralWhite: '#FFFAF0', ForestGreen: '#228B22', Fuschia: '#FF00FF', Gainsboro: '#DCDCDC', GhostWhite: '#F8F8FF', Gold: '#FFD700', GoldenRod: '#DAA520', Grey: '#808080', Green: '#008000', GreenYellow: '#ADFF2F', HoneyDew: '#F0FFF0', HotPink: '#FF69B4', IndianRed: '#CD5C5C', Indigo: '#4B0082', Ivory: '#FFFFF0', Khaki: '#F0E68C', Lavender: '#E6E6FA', LavenderBlush: '#FFF0F5', LawnGreen: '#7CFC00', LemonChiffon: '#FFFACD', LightBlue: '#ADD8E6', LightCoral: '#F08080', LightCyan: '#E0FFFF', LightGoldenRodYellow: '#FAFAD2', LightGrey: '#D3D3D3', LightGreen: '#90EE90', LightPink: '#FFB6C1', LightSalmon: '#FFA07A', LightSeaGreen: '#20B2AA', LightSkyBlue: '#87CEFA', LightSlateGrey: '#778899', LightSteelBlue: '#B0C4DE', LightYellow: '#FFFFE0', Lime: '#00FF00', LimeGreen: '#32CD32', Linen: '#FAF0E6', Magenta: '#FF00FF', Maroon: '#800000', MediumAquaMarine: '#66CDAA', MediumBlue: '#0000CD', MediumOrchid: '#BA55D3', MediumPurple: '#9370DB', MediumSeaGreen: '#3CB371', MediumSlateBlue: '#7B68EE', MediumSpringGreen: '#00FA9A', MediumTurquoise: '#48D1CC', MediumVioletRed: '#C71585', MidnightBlue: '#191970', MintCream: '#F5FFFA', MistyRose: '#FFE4E1', Moccasin: '#FFE4B5', NavajoWhite: '#FFDEAD', Navy: '#000080', OldLace: '#FDF5E6', Olive: '#808000', OliveDrab: '#6B8E23', Orange: '#FFA500', OrangeRed: '#FF4500', Orchid: '#DA70D6', PaleGoldenRod: '#EEE8AA', PaleGreen: '#98FB98', PaleTurquoise: '#AFEEEE', PaleVioletRed: '#DB7093', PapayaWhip: '#FFEFD5', PeachPuff: '#FFDAB9', Peru: '#CD853F', Pink: '#FFC0CB', Plum: '#DDA0DD', PowderBlue: '#B0E0E6', Purple: '#800080', Red: '#FF0000', RosyBrown: '#BC8F8F', RoyalBlue: '#4169E1', SaddleBrown: '#8B4513', Salmon: '#FA8072', SandyBrown: '#F4A460', SeaGreen: '#2E8B57', SeaShell: '#FFF5EE', Sienna: '#A0522D', Silver: '#C0C0C0', SkyBlue: '#87CEEB', SlateBlue: '#6A5ACD', SlateGrey: '#708090', Snow: '#FFFAFA', SpringGreen: '#00FF7F', SteelBlue: '#4682B4', Tan: '#D2B48C', Teal: '#008080', Thistle: '#D8BFD8', Tomato: '#FF6347', Turquoise: '#40E0D0', Violet: '#EE82EE', Wheat: '#F5DEB3', White: '#FFFFFF', WhiteSmoke: '#F5F5F5', Yellow: '#FFFF00', YellowGreen: '#9ACD32' }; // cb.settings_choices = [ {name:'cst', type:'int', minValue:0, maxValue:999, default:10, label: 'Missile Cost (0-999)'}, //{name: 'hashtags', type: 'str', label: 'Hashtags', defaultValue:'#sexy #strip #pussy #cumshow #dildo #boobs #wet #sex'}, {name: 'prize_1', type: 'str', label: '1st sink prize'}, {name: 'prize_2', type: 'str', label: '2nd sink prize'}, {name: 'prize_3', type: 'str', label: '3rd sink prize'}, {name: 'prize_4', type: 'str', label: '4th sink prize'}, {name: 'grand_prize', type: 'str', label: 'Grand prize (all boats sunken)'}, {name: 'text_color', label: 'Text Color', type: 'choice', choice1: 'Black', choice2: 'Red', choice3: 'Green', choice4: 'Blue', choice5: 'OrangeRed', choice6: 'MediumBlue', choice7: 'Cyan', choice8: 'MediumSpringGreen', choice9: 'RoyalBlue', choice10: 'Violet', defaultValue: 'Black' }, ]; cb.onEnter(function(user) { if (user['has_tokens']&&shp.length) cb.chatNotice('*** A Raiders of the Battleship game is in progress. tip '+cb.settings.cst+' tokens to fire a missile. Type /prizes to see the prizes and /board to see the current board.',user['user'],'','','bold'); }); cb.onTip(function (tip) { if (tip['amount']>=cb.settings.cst&&tip['message'].match(/^[A-I]{1}[1-9]{1}$/gi)) { //regex a1-i9 ret = takeInput(tip['message']); cb.chatNotice('*** '+ret.message,'','','','bold'); showBoard(); if (ret.prize!=null) { cb.sendNotice(tip['from_user']+' '+ret.prize, '', '#99FF99', '', 'bold'); } } tct += tip['amount']; }); cb.onMessage(function (msg) { //if (/(?:camshacks|danacamsessions|girls4party|nude4strip).*c[o0]m/ig.test(msg['m'])) msg['X-Spam'] = true; //block spam if (msg['m']=='/board') { msg['X-Spam'] = true; showBoard(msg['user']); } else if (msg['m']=='/newgame'&&msg['user']==cb.room_slug&&!shp.length) { msg['X-Spam'] = true; cb.chatNotice('*** Broadcaster has begun a new round of Battleship!','','','','bold'); initGame(); } else if (msg['m']=='/prizes') { msg['X-Spam'] = true; showPrizes(msg['user']); } else if (msg['m']=='/help'||msg['m']=='/rules') { msg['X-Spam'] = true; cb.chatNotice('*** Legend: _ indicates an unhit location, X is a hit, 0 is a miss | Type /prizes to see what you can win.',msg['user']); } else if (msg['m']=='/about') { msg['X-Spam'] = true; cb.chatNotice('*** BATTLESHIP '+rls+' by slavabo (botted by indshadow).','','','bold'); } return msg; }); function createShip(ssz) { if (ssz>bsz-1) ssz = bsz-1; reroll: do { var tmp = [ssz]; do { var p1b=p1e=Math.floor((Math.random()*bsz)); var p2b=p2e=Math.floor((Math.random()*bsz)); } while (brd[p1b][p2b]=='X'); tmp.push(ltr[p1b]+(p2b+1)); switch (Math.floor((Math.random()*2))) { case 0: //vertical for (var aaa=0;aaa<ssz-1;aaa++) { if ((p1b==0)||((Math.floor((Math.random()*2))&&p1e+1<bsz)&&(brd[p1e+1][p2e]!='X'))) { if (brd[p1e+1][p2b]=='X') continue reroll; p1e++; tmp.push(ltr[p1e]+(p2e+1)); } else { if (brd[p1b-1][p2b]=='X') continue reroll; p1b--; tmp.push(ltr[p1b]+(p2b+1)); } brd[p1b][p2b]='X'; brd[p1e][p2e]='X'; } break reroll; case 1: //horizontal for (var aaa=0;aaa<ssz-1;aaa++) { if ((p2b==0)||((Math.floor((Math.random()*2))&&p2e+1<bsz)&&(brd[p2e+1][p2e]!='X'))) { if (brd[p1b][p2e+1]=='X') continue reroll; p2e++; tmp.push(ltr[p1e]+(p2e+1)); } else { if (brd[p1b][p2b-1]=='X') continue reroll p2b--; tmp.push(ltr[p1b]+(p2b+1)); } brd[p1b][p2b]='X'; brd[p1e][p2e]='X'; } break reroll; } } while (!0); shp.push(tmp); } function showBoard(user) { var sbm = spc+spc; for (var aaa=0;aaa<bsz;aaa++) { for (var bbb=0;bbb<bsz;bbb++) { sbm += brd[aaa][bbb]+spc+spc+spc; } sbm += '| '+ltr[aaa]+'\n'+spc+spc; } for (aaa=1;aaa<=bsz;aaa++) sbm += aaa+spc+spc+spc; sbm += '('+shp.length+' ship'; if (shp.length>1) sbm+= "s"; sbm += ' remaining)\nLegend: X = hit, o = miss | Type /help for more info'; if (user) cb.chatNotice(sbm,user,'',colors[cb.settings.text_color]); else cb.chatNotice(sbm,'','',colors[cb.settings.text_color]); } function showPrizes(username) { var notices = '**** Possible Prizes ****\n'; notices += '1st sink - ' + cb.settings.prize_1 + '\n'; notices += '2nd sink - ' + cb.settings.prize_2 + '\n'; notices += '3rd sink - ' + cb.settings.prize_3 + '\n'; notices += '4th sink - ' + cb.settings.prize_4 + '\n'; notices += 'Win game (all 5 sunken) - ' + cb.settings.grand_prize; cb.sendNotice(notices, username, '#D1F0FF', '', 'bold'); } function takeInput(loc) { loc=loc.toUpperCase(); var prizemsg = null; act = new Date().getTime(); if (brd[fromLetter(loc.charAt(0))][loc.charAt(1)-1]!="_") return loc+" has already been guessed. Tip forfeited."; else if (shp.join().indexOf(loc)==-1) { //no ship at location tim = 'Sorry, '+loc+' is a miss. Better luck next time!'; brd[fromLetter(loc.charAt(0))][loc.charAt(1)-1]='o'; } else { baseloop: for (var aaa=0;aaa<shp.length;aaa++) { for (var bbb=1;bbb<shp[aaa].length;bbb++) { if (shp[aaa][bbb]===loc) { shp[aaa][0]--; if (!shp[aaa][0]) { //ship sunk var ssz = shp[aaa].length-1; shp.splice(aaa,1); if (!shp.length) { //no more ships //cb.changeRoomSubject("Raiders of the Battleship - Game Over. Thanks For Tipping!"+ cb.settings.hashtags); tim = loc+" is a hit and sink! There are no remaining ships on the board."; prizemsg = 'won the grand prize! '+cb.settings.grand_prize+'!'; cb.chatNotice('*** Type /newgame to begin a new game of Battleship.',cb.room_slug,'','','bold'); } else { if (shp.length == 4) { prize = cb.settings.prize_1; } else if (shp.length == 3) { prize = cb.settings.prize_2; } else if (shp.length == 2) { prize = cb.settings.prize_3; } else if (shp.length == 1) { prize = cb.settings.prize_4; } prizemsg = 'won a prize! ' + prize; tim = loc+" is a hit and has sunk a 1x"+ssz+" sized "+shipName(ssz)+"!"; } } else tim = loc+" is a hit! Keep firing, the ship is still afloat."; break baseloop; } } } brd[fromLetter(loc.charAt(0))][loc.charAt(1)-1]='X'; } return { message: tim, prize: prizemsg } } function fromLetter(ltr) { switch (ltr) { case "A": return 0; case "B": return 1; case "C": return 2; case "D": return 3; case "E": return 4; case "F": return 5; case "G": return 6; case "H": return 7; case "I": return 8; } } function shipName(ssz) { switch (ssz) { case 2: return 'Destroyer'; case 3: return 'Cruiser'; case 4: return 'Battleship'; case 5: return 'Carrier'; default: return 'Unknown Ship'; } } function initGame() { //cb.changeRoomSubject("Raiders of the Battleship - tip "+cb.settings.cst+" tokens to fire a missile. " + cb.settings.hashtags); shp = []; brd = [[],[],[],[],[],[],[],[],[]]; //Populate ship coordinates; largest to smallest createShip(5); createShip(4); createShip(3); createShip(3); createShip(2); //Zero out status board; must occur after createShip() for (var aaa=0;aaa<bsz;aaa++) for (var bbb=0;bbb<bsz;bbb++) { brd[aaa][bbb] = "_"; //"fill" character } showBoard(); act = new Date().getTime(); counter(); /* var tex = '' var nu = 1 for(var key in colors) { tex = nu + '. Hello_X_o...' + key; cb.sendNotice(tex,'','',colors[key]); nu++; } */ } function counter() { if (!shp.length) return false; if (new Date().getTime()-act>=300000) { cb.chatNotice('Try your chance at sinking a ship- tip *'+cb.settings.cst+'tkn* to fire a missile! Type /prizes to see the prizes and /board to see the board','','','','bold'); showBoard(); cb.setTimeout(counter,300000); } else cb.setTimeout(counter,300000-(new Date().getTime()-act)); } // initGame();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.