What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [release] Tic Tac Toe 2

[release] Tic Tac Toe 2
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [release] Tic Tac Toe 2
quote:
Originally posted by deAd
quote:
Originally posted by SpunkyLoveMuff
code:
var SW_MINIMIZE = 0x6;
Interop.Call('user32', 'ShowWindow', game.Handle, SW_MINIMIZE);


Why not:
code:
Interop.Call('user32', 'ShowWindow', game.Handle, 0x6);


in my opinion its better/more convenient to use constants like that, however I'd declare them globally instead of locally in the function :/

If it is just for 1 line of code, like in this script, you can do something like:

Interop.Call('user32', 'ShowWindow', game.Handle, /* SW_MINIMIZE */ 0x6);

-------------------------------------------------------------

anyways, roflmao456

some tips:

- Start by indenting lines of code properly with tabs. This will make possible errors and optimizations visible in an instant.

- Remove the need for all those global variables. You will need some global variables, but not all of those.

- Declaring an activex object in global space isn't needed at all. Declare it where you need it.

- Use an array as your play grid instead of all those sequencial variables a1, a2, a3, b1, b2, etc...

- Determining who won can be made shorter. And it also contains a duplicated check for both sides btw.

Don't check each side individually, but simply check if squares are equal (using the method above). And if they are, only then determine to which side the squares are belonging. In other words, use the opposite of the logic you use now. This will make the whole checking faster and shorter and will reduce the needed checks from the currently 18 to 8 checks.

And if you take in account the last move (which is the only one which might trigger a win situation of course) and you use an array as your playing grid you could reduce this even further to only 3 or 4 checks (for a horizontal, a vertical and a diagonal solution).

So you don't need all those checks since the only way that someone can have 3 in a row is when the middle square of the sequence is equal to the left and right side square of it, or upper and lower side of it, or up-left and down-right, or down-left and up-right. And if so, any of the three squares making a solution will always hold the sign of the winning party. Or even shorter: if a winning solution is made, the winning party will always be the one who last made a move, thus you actually don't even need to check the signs in the squares.

- Some code in checkWin() is also duplicated, so remove that and put it above the structure where it is nested in (the alertmsg and canMove variables).

In addition to this, since the only thing you change in the         if(won == "O"){} check is the name of the side that won, you can easly remove that check and simply place won as a variable in that sentence since it already identifies who won.

- In the OnEvent_Timer(timerId) function replaces those if_then_else's with a switch statement.

- Change the "!tic-tac-toe" command to "/tic-tac-toe". Commands in Plus! start with "/", so that is what the user is used to.
(and personally I would remove the "-" in the command, but that's just pure personal preference)

- Take in account that the user can type commands in uppercase to. So add a .tolowercase() to the command catching routines.

- The rest is just a big mess in code atm and I cba to fix all the indenting first to check the code further, see point 1 ;)

- Change things like:
code:
if (Origin != Messenger.MyName) {
    if (Message.substr(0,12) == "!tic-tac-toe"){
    }
}
if (Origin == Messenger.MyName){
    if (Message.substr(0,12) == "!tic-tac-toe"){
    }
}
to:
code:
if (Message.substr(0,12) === "!tic-tac-toe"){
    if (Origin === Messenger.MyName) {
    } else {
    }
}
which is shorter and easier to maintain.

- Chage stuff like
code:
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!b1"){
if(Message.substr(0,3)!="!b2"){
if(Message.substr(0,3)!="!b3"){
if(Message.substr(0,3)!="!c1"){
if(Message.substr(0,3)!="!c2"){
if(Message.substr(0,3)!="!c3"){
//dosomething
}}}}}}}}}
to at least 1 check using an AND operator.
Or better yet, use a single regular expression.

Also you use such a bunch of checks twice inside an if_then_else, once for the true part and once for the false part. So switch this logic around and use those bunch of checks as the first main checks and only then do the check you otherwise did first (if(chat.GetControlText("chatAll")){).


- the design of the game window is nice (y)

This post was edited on 12-13-2006 at 02:49 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
12-13-2006 01:52 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[release] Tic Tac Toe 2 - by roflmao456 on 12-12-2006 at 11:18 PM
RE: [release] Tic Tac Toe 2 - by DarkMe on 12-12-2006 at 11:40 PM
RE: [release] Tic Tac Toe 2 - by Spunky on 12-12-2006 at 11:57 PM
RE: RE: [release] Tic Tac Toe 2 - by deAd on 12-13-2006 at 12:44 AM
RE: [release] Tic Tac Toe 2 - by CookieRevised on 12-13-2006 at 01:52 AM
RE: [release] Tic Tac Toe 2 - by Spunky on 12-13-2006 at 02:07 AM
RE: RE: [release] Tic Tac Toe 2 - by deAd on 12-13-2006 at 02:58 AM
RE: [release] Tic Tac Toe 2 - by CookieRevised on 12-13-2006 at 02:11 AM
RE: [release] Tic Tac Toe 2 - by Spunky on 12-13-2006 at 04:01 AM
RE: [release] Tic Tac Toe 2 - by roflmao456 on 12-13-2006 at 11:44 PM
RE: RE: [release] Tic Tac Toe 2 - by CookieRevised on 12-19-2006 at 02:41 AM
RE: [release] Tic Tac Toe 2 - by NanaFreak on 12-13-2006 at 11:53 PM
RE: RE: [release] Tic Tac Toe 2 - by roflmao456 on 12-13-2006 at 11:55 PM
RE: [release] Tic Tac Toe 2 - by NanaFreak on 12-14-2006 at 12:02 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On