Labdabeta 182 Posting Pro in Training Featured Poster

Think about it logically. You have O(N) executions of loop N and N executions of loop M. I would think that the complexity then would be O((N^2)M) of course I do not really know much about big-O notation (I just self-taught myself it) does anybody know if O((N^2)M) is right, or any good resources for learning big-O notation?

Labdabeta 182 Posting Pro in Training Featured Poster

I am not sure I understand. Why can't you just do this:

cout<<"<"<<"$"<<endl;
Labdabeta 182 Posting Pro in Training Featured Poster

Have you tried debugging?

Labdabeta 182 Posting Pro in Training Featured Poster

Do not ask for code. Suggestions are fine. I would suggest using a 256-base system and store the digits in an std::string. Make this into a class with all the normal arithmetic operators defined. Next add a function called factorial (or maybe overload the ! operator?) and write the traditional factorial code there.

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,
I have been working with opengl and other graphics libraries and they all require the bits per pixel of the screen on initialization of a window. My question is, is there any way to get the system's preffered bits per pixel? or that of the monitor?

Labdabeta 182 Posting Pro in Training Featured Poster

This code looks fine to me. If you wrap it into classes it could be even better, then you could probably add functionality for fitting the objects into the container (since usually not every square meter of the container is filled). I would suggest a containerItem class and a container class like this:

struct containerItem
{
    double width,height,length;
};
class container
{
    private:
    containerItem dimensions;
    public:
    container(containerItem dimensions):dimensions(dimensions){}
    double calculateCost(containerItem i);
};
Labdabeta 182 Posting Pro in Training Featured Poster

My guess is that your HowMuchDataInFile function needs to return the value - 1 because of the name of the city occupying the first line of the file. IE: return howmuch-1;

Labdabeta 182 Posting Pro in Training Featured Poster

Well your code would be easier to understand in english. I can sort of assume what each function and/or variable will do, but it is hard in lithuanian.

Labdabeta 182 Posting Pro in Training Featured Poster

I am not entirely certain, but maybe the problem has to do with the unusual characters? You may need to store them in an int and not a char to allow for long unicodes. It may be easier if you translate the code into english.

Labdabeta 182 Posting Pro in Training Featured Poster

Well... I got one working, it technically meets the requirements... but I don't count it as a true solution.

void drawTree(int n)
{
    if (n<0)
    {
        for (int i=n; i<0; ++i)
            cout<<"*";
        cout<<endl;
        drawTree(n+1);
    }
    if (n>0)
    {
        drawTree(n-1);
        for (int i=1; i<n; ++i)
            cout<<"*";
        cout<<endl;
    }
}
void drawMeATree(int n)
{
    drawTree(n);
    drawTree(-n);
}

I just don't like it because it is based on a dual call, but as proven above it would be completely impossible to do this as a single traditional recursive call. But to recap, a recursive call by definition calls itself, but with different arguments. Since writing to the console is linear, we can only append to it (that means no going back, or shifting at all) unless we can 'tack' something to the start or the end of the output of the call to change it to another call, we are unable to complete the problem.

Labdabeta 182 Posting Pro in Training Featured Poster

The problem with incrementing n, even if you decrement it is that you end up with an infinite loop because each time the function is called n will continue to increase until you get to n=some really big number, at which point n will become negative and you will have a console filled to the brim with asterisks. I thought that it should be possible too, but if you think about it using reductio ad absurdum you get:

Assuming drawTree(X) draws the desired pattern by drawing a smaller tree, since the pattern takes the form (replacing n asterisks with merely n and new lines with commas):

drawTree(X)=1,2,3,...,n-2,n-1,n,n-1,n-2,...,3,2,1

to define the call recursively we would require:

drawTree(X)=something or nothing,drawTree(something or nothing, but not this),something or nothing

since we require that only the first and last values are 1 we need drawTree at the ends:

nothing,drawTree(something or nothing),nothing

This leads to a tautological statment that:

drawTree(X)=drawTree(something or nothing, but not this)
drawTree(X)=drawTree(not X)

Since drawTree is 'one-to-one' we know that drawTree(X) cannot equal anything but drawTree(X). Since when we assumed the problem was possible we ran into a contradiction the problem itself therefore must be contradictory.

Incidentally I was able to get code that would draw the top, OR the bottom of the tree, but not both. I cannot think of any way that it could be possible, as you can see in a fairly well-reasoned proof above. The proof does …

Labdabeta 182 Posting Pro in Training Featured Poster

I was just thinking... without some kind of hack of some format this is impossible. Just think about it. if calling starTree(5) gives:
*
**
***
****
*****
****
***
**
*

and calling starTree(4) gives:
*
**
***
****
***
**
*

Since starTree(4) is in no way part of starTree(5) at least linearly, this leaves but two options:
1) Platform specific console commands to shift the position of the put cursor.
2) Storing the data, either as another parameter, or a global variable or something
3) I cannot think of anymore, but I love to find out that I am wrong.

Here are a couple ways to do number 2:

//if initially int was the limit, we can use the upper bit of
//  this version of n to store the initial value
void drawTree(unsigned int n)
{
    if (!(n&0xFFFF0000))//this is the first call
        n|=(n<<16);//if n WAS 0x0000WXYZ now it IS 0xWXYZWXYZ
    int val=(int)(n&0x0000FFFF);//just get THIS n
    int start=(int)(n&0xFFFF0000);
    start>>=16;//lets go back
    if (val)//AKA: if (val!=0)
    {
        /*Apparently ++i is better than i++ because
         *  i++ requires that a copy of i be temporarily
         *  created. Though with ints this is avoided by
         *  the compiler, ++i is at least as fast if not
         *  faster than i++. This is especially true for
         *  complex data types, but it is not all that
         *  important. …
Labdabeta 182 Posting Pro in Training Featured Poster

Hmmm... in that case, unless you get off on a technicality you will need iterative recursion. This is where you make a recursive call in a loop. I am working on the solution myself... I happen to have trouble with iterative recursion.

Labdabeta 182 Posting Pro in Training Featured Poster

You may need two parameters. Here is an example that should help you along a bit:

void recursiveTest(int val, int start)
{
    if (val==0)
    {
        cout<<"Pivotting..."<<endl;
    }
    else
    {
        cout<<"Winding up, time #"<<start-val<<"..."<<endl;
        recursiveTest(val-1,start);
    }
    cout<<"Unwinding, time #"<<start-val<<"..."<<endl;
}
void callRecursiveFunction(int val)
{
    recursiveTest(val,val);
}
Labdabeta 182 Posting Pro in Training Featured Poster

Is this a viable BIGENDIAN test:

int tmpvaluethatwillneverreallybeused=1;
bool bigendian=(*(char*)(&tmpvaluethatwillneverreallybeused)==1);
void myFunction()
{
    if (bigendian)
    {
        //do big endian specific code
    }
    else
    {
        //do little-endian specific code
    }
}
Labdabeta 182 Posting Pro in Training Featured Poster

Try running this code and see what you can make of it:

void recursiveTest(int cntr)
{
    if (cntr==0)
    {
        cout<<"Pivotting..."<<endl;
    }
    else
    {
        cout<<"Winding up..."<<endl;
        recursiveTest(cntr-1);
    }
    cout<<"Unwinding..."<<endl;
}
int main()
{
    recursiveTest(5);
    return 0;
}
Labdabeta 182 Posting Pro in Training Featured Poster

I was thinking of rather than storing a char** to store a single char* string with some delimiting character. I really need a dynamic array of strings so I do not see any other choice.

Labdabeta 182 Posting Pro in Training Featured Poster

I have some code in C++ that uses an std::vector of std::strings to store an array of strings. I need to convert it into C. I thought that I would just create c versions of the functions I need (vector.back,vector.push_back,string.operator+=) but am getting lost in the double pointers. Can anybody lead me on the right track here?

Labdabeta 182 Posting Pro in Training Featured Poster

I just thought I would share what I got working so far. Here is a sample quine in my modified version of the brainfuck language:

#include "ParseBrainFuck.h"//lol, nicely done daniweb on the IN-CODE consorship! :) My code uses the actual letters, not * so it actually works
int main()
{
    //Is a quine!!!
    bfCompile(":\
              \
              'DATA'\
              >}>>}>>}0>}}>}:>}.>}_>}>>}[>})>}X>}0>}}>}>>}.>}0>}}>}}>}.>}(>}X>}.>}>>}]>}_>}>>}[>}.>}>>}]\
              'OUTPUT'\
              >>0}:.'The initial colon needs to be outputted.'\
              _>['Start the output loop. Believe it or not we are now sitting at the start of the double data'\
                )X'Shift ahead of our data'\
                0}>.'Output the initial > character.'\
                0}}.'Output the initial } character.'\
                (X'Shift back'\
                .'Output the character.'\
                >'Shift to the next character.'\
                ]\
              _>['Now just output the values'\
                .\
                >\
                ]\
                    ");
    return 0;
}

Using a modified c++ highlighter, if I remove the \ after the : then I get properly highlighted code. Thanks for the help!

Labdabeta 182 Posting Pro in Training Featured Poster

Well I was hoping to be able to have in-line language parsing, so that I can switch between the languages on a whim. Right now I have it fully functional is the form of Compile(const char*) but that requires unusual escape characters and a complete nullification of syntax highlighting. Perhaps I will look into Code::Blocks compiler options and see if I can throw my own executable in before gcc. Thank you.

Labdabeta 182 Posting Pro in Training Featured Poster

Is there any way to add my own language to code::blocks, that way it could get the highlighting right and maybe I can define a compiler for it to use?

Labdabeta 182 Posting Pro in Training Featured Poster

How do I build a simple compiler? I think that that would be exactly what I would need.

Labdabeta 182 Posting Pro in Training Featured Poster

That was helpful, but it didn't exactly solve my problem. I want to be able to write code like this (C++ example):

#define myLanguage(X) myCPPCompiler(#X)//I need this to actually work somehow
myLanguage(//assuming my language is c++ at this point
    int temp=0,temp2=0;
    cin>>temp,temp2;
    cout<<temp*temp2;
)
Labdabeta 182 Posting Pro in Training Featured Poster

I want to be able to write a different language into my c++ code. Something like the __asm() function. The thing is that I was wondering if I could tell the compiler to ignore normal syntax rules so that I could do something like this:

int main()
{
    myLanguageTranslator(
        please realize that this is supposed to be viable code in
         another programming language. I just want to be able to do "this"
         without needing escape characters, is it at all possible?
    );
    return 0;
}
Labdabeta 182 Posting Pro in Training Featured Poster

I was wondering if there is any way using the mingw g++ compiler to make code that acts like this:

#define myLanguageBlock(X) doMyLanguageBlock(#X)
void doMyLanguageBlock(const char* code){/*this executes the code as if it were in another language, I have already written this function*/}
int main()
{
    myLanguageBlock(
        this is all code written in my language. It has comma's, periods, and {brackets)][);
    return 0;
}

I am having trouble figuring this one out.

Labdabeta 182 Posting Pro in Training Featured Poster

I see two ways of doing this. Either read the entire contents of the file into a string and then break the string apart, or use file seeking functionality. Here is an example of the file seeking functionality for n=3 strings:

FILE *file=fopen(filename,"r");
if (!file)return;
char buffer[4];//this will store our strings
while (!feof(file))
{
    fgets(buffer,3,file);
    fseek(file,-1,SEEK_CUR);
    //add buffer to the list of return values
}
Labdabeta 182 Posting Pro in Training Featured Poster

How do I do assembly code with the mingw-g++ compiler. All the websites I checked say that this should work:

int add(int a, int b)
{
    int c=0;
    asm("mov %[aVal],%eax;add %[bVal],%eax;mov %eax,%[cVal]"
        : [cVal] "=i" (c)
        : [bVal] "i" (b)
        : [aVal] "i" (a));
    return c;
}

But instead I get the following compiler errors:
D:\Programming\C++\test\main.cpp||In function 'int add(int, int)':|
D:\Programming\C++\test\main.cpp|10|error: expected string-literal before '[' token|
D:\Programming\C++\test\main.cpp|10|error: expected ')' before '[' token|
D:\Programming\C++\test\main.cpp|10|error: undefined named operand 'aVal'|
D:\Programming\C++\test\main.cpp|4|warning: unused parameter 'a'|
||=== Build finished: 3 errors, 1 warnings ===|

What is wrong with that code? How do I do assembly in c++?

Labdabeta 182 Posting Pro in Training Featured Poster

I am working on this because it looks like fun. I am just wondering what the challenge is, implementation wise. I have a BoggleBoard class now, and a function in it called getAllMoves() this function takes an array of c-style strings and an integer array length. Should I return an array of the possible c-style strings that can be made using the tiles on the board, or should I return just the best possible word, or what?

Labdabeta 182 Posting Pro in Training Featured Poster

Thank you, that was very informative.

Labdabeta 182 Posting Pro in Training Featured Poster

I was just wondering how exit worked? Does it use some lower-level language feature in its implementation? Is it compiler-specific? What is it? (I am talking about the function in stdlib.h btw)

Labdabeta 182 Posting Pro in Training Featured Poster

I decided to try converting the code to java because it has simpler inheritance, and it worked. My problem was a little bit too much shallow copying! Thanks for the help!

Labdabeta 182 Posting Pro in Training Featured Poster

Thank you, that was very helpful! I am going to go for enums (when possible) and otherwise create a simple container class if there are many things to represent.

Labdabeta 182 Posting Pro in Training Featured Poster

You would need a boolean value to store the state of the primality of the number. A simpler approach is to use a function, which hopefully you have learned. This is what I usually use for a primality check:

bool isPrime(int x)//checks if x is a prime number
{
    for (int i=2; i*i<x; i++)//loop from 2 to SQRT(X)
    {
        if (x%i==0)
            return false;//its definately NOT prime
    }
    //the fact that we even made it here means that it is prime!
    return true;
}
Labdabeta 182 Posting Pro in Training Featured Poster

If it is that urgent, this can be done quickly and easily using the dreaded global variable. Not to recommend extensive use of globals but just this once they could make for an easy solution:

int f1,f2;
void functionOne(/*functionOne arguments*/)
{
    f1++;//increment f1
    //code for function One
}
void functionTwo(/*functionTwo arguments*/)
{
    f2++;//increment f2
    //code for function Two
}
void showCounts()
{
    cout<<"functionOne: "<<f1<<" times.\nfunctionTwo: "<<f2<<" times.";
}
int main()
{
    showCounts();
    functionOne();
    showCounts();
    functionTwo();
    showCounts();
    return 0;
}

That is just an example of course, but you can use this principle in your code if you need to.

Labdabeta 182 Posting Pro in Training Featured Poster

I am sorry to keep reposting like this, but I have added some comments to my code:

class IAlphaBetaPlayer:public IGamePlayer
{
    protected:
    MoveScore AlphaBeta(IGameState &current, int ply, bool us, double alpha, double beta)
    {
        MoveScore best={NULL,-DBL_MAX};//default value: no move, -infinity
        if (ply<=0||current.gameOver())//this is the exit condition for rthe recursion
        {
            best.score=(us?evaluate(current):negEvaluate(current));//get the score of this state.
            return best;
        }
        int numMoves;
        GameMove *moves=(us?getMoves(current,numMoves):getTheirMoves(current,numMoves));//get a list of available moves
        for (int i=0; i<numMoves; ++i)//for each move
        {
            current.execute(moves[i]);
            MoveScore tmp=AlphaBeta(current,ply-1,!us,-beta,-alpha);//recurse using the state after the move, one less ply and swapped ab
            current.undo(moves[i]);//reset the game state
            if ((-tmp.score)>best.score)//this is the new best move as it makes their score less
            {
                alpha=(-tmp.score);//set the new alpha value
                best.move=moves[i];//save the move
                best.score=alpha;//and the score
            }
            if (alpha>=beta)//no matter what we will not be able to find a value greater than alpha and less than beta
            {
                return best;
            }
        }
        return best;
    }
    public:
    virtual GameMove getMove(IGameState &g){
        return AlphaBeta(*(g.clone()),ply(),true,-DBL_MAX,DBL_MAX).move;
    }
    virtual double evaluate(IGameState &)=0;
    virtual double negEvaluate(IGameState &)=0;
    virtual GameMove *getMoves(IGameState &,int &)=0;
    virtual GameMove *getTheirMoves(IGameState &, int &)=0;
    virtual int ply()=0;
};

Perhaps that will help you sort out the problem? I am still looking for it, but it is a stealthy one!

Labdabeta 182 Posting Pro in Training Featured Poster

But wouldnt an enum be limited to the size of an int. I need to be able to store a massive set of independent values, 32 bits will not be enough.

Labdabeta 182 Posting Pro in Training Featured Poster

I really cannot see what is wrong... the evaluator seems functional but I tried looking at the alphabeta algorithm and it seems to be working incorrectly. I really need this program to work.

Labdabeta 182 Posting Pro in Training Featured Poster

As I understood it 0 is the same as '\0' and NULL is defined as (void*)0. As an ASCII character though '\0' is used to terrminate a string.

Labdabeta 182 Posting Pro in Training Featured Poster

Now deceptikon and DeanMSands3 seem to disagree. DeanMSands3 said:

#3 will use more memory at run-time since it allocates the const chars then references them (i.e. comparing by reference).
At the CPU level, this makes a world of difference. Since the CPU has to access the memory to get the number you're referencing, it will take more time to process it as opposed to you simply handing it the number.

and deceptikon said:

const variables are preferred over macros because their names aren't lost during preprocessing. One of the biggest problems with macros is difficulty in debugging code where a macro is involved. Making const a compile time constant was intended to replace non-function-like macros.

...

There's not going to be a significant enough difference for you to worry about it. Don't sweat the small stuff, data structure and algorithm choices make up the lion's share of performance and storage costs.

Labdabeta 182 Posting Pro in Training Featured Poster

Thanks, I tend to like using macros because that way they can fit into whatever type I need. I do not know the limit of enum values, but I have ended up with key values as high as 0x100000000000 and higher. Thanks.

Labdabeta 182 Posting Pro in Training Featured Poster

I need to know which of these three copies of code is considered best. I also need to which one is more efficient memory wise and which is more efficient time wise. Thanks:
enums

enum MyEnum{EnumTypeOne=1,EnumTypeTwo=2,EnumTypeThree=4,EnumTypeFour=8};

macros

#define EnumTypeOne 1
#define EnumTypeTwo 2
#define EnumTypeThree 4
#define EnumTypeFour 8
typedef char MyEnum;

constants

const char EnumTypeOne=1;
const char EnumTypeTwo=2;
const char EnumTypeThree=4;
const char EnumTypeFour=8;
typedef char MyEnum;
Labdabeta 182 Posting Pro in Training Featured Poster

Thank you!

Labdabeta 182 Posting Pro in Training Featured Poster

I was working on a project when I thought that maybe a ::. operator would look funny in some code. Just for fun I typed that into the global scope area like this:

::.
int main()
{
//etc...

and my code completion software said too many results to display. My question is what results could it be talking about? Is it possible to define global operators?

Labdabeta 182 Posting Pro in Training Featured Poster

I have implemented another evaluator, but I am having the trouble that AlphaBeta is returning a score of zero consistently until the final move. I cannot figure out why?!

Labdabeta 182 Posting Pro in Training Featured Poster

Also I have tried analysing the score part of the AlphaBeta function in my debugger and it always seems to return either 0, -0, or 100, but no values in between (this is in the getMove() function) I have not fully stepped through AlphaBeta itself because the iterative recursion makes it take for ever!

Labdabeta 182 Posting Pro in Training Featured Poster

I tried your suggestion and it does seem like some of the bad moves are getting better scores. I just can't think of a better evaluator, do you have any ideas? Also why is the code that is commented out not working (its causing a sigseg)?

Labdabeta 182 Posting Pro in Training Featured Poster

Ok, I improved it a bit (noticed a few other problems too, along with your suggestion) here is the resulting class:

class StaticTicTacToe:public IAlphaBetaPlayer
{
    private:
    bool isX;
    LABRandom r;
    public:
    StaticTicTacToe(bool isX):isX(isX),r(){}
    virtual double evaluate(IGameState &gs)
    {
        if (gs.ID()!=TICTACTOEID)
            return 0.0;
        char *s=(char*)gs.data;
        //get all possible three in a rows
        char tiars[8][3]={ {s[0],s[1],s[2]},{s[3],s[4],s[5]},{s[6],s[7],s[8]},
                           {s[0],s[4],s[8]},{s[2],s[4],s[6]},{s[0],s[3],s[6]},
                                {s[1],s[4],s[7]},{s[2],s[5],s[8]}};
        double ret=50.0;
        if ((s[0]=='O'||s[2]=='O'||s[6]=='O'||s[8]=='O')&&s[4]!='X'&&isX)
            return 0.01;//we will lose if they are smart...
        if ((s[0]=='X'||s[2]=='X'||s[6]=='X'||s[8]=='X')&&s[4]!='O'&&!isX)
            return 0.01;//we will lose if they are smart...
        for (int i=0; i<8; i++)//loop through the three in a rows
        {
            //1st check for win
            if (tiars[i][0]==tiars[i][1]&&tiars[i][1]==tiars[i][2]&&tiars[i][0]!=' ')
            {
                if (tiars[i][0]=='X')
                    return (isX?100.0:0.0);
                else
                    return (isX?0.0:100.0);
            }
            else//now find out how many of each player's marks are in each three in a row
            {
                int numx=0;
                int numo=0;
                for (int ii=0; ii<3; ii++)
                {
                    if (tiars[i][ii]=='X')
                        numx++;
                    if (tiars[i][ii]=='O')
                        numo++;
                }
                if (isX)
                {
                    if (numx==0&&numo==2)
                        ret-=0.50;//they will likely win!
                    else if (numx==0&&numo==1)
                        ret-=(tiars[i][1]=='O'?5.0:15.0);//they still have a claim on this three in a row!
                    else if (numo==0)
                    {
                        if (numx==2)//we have two in a row!
                        {
                            if (tiars[i][1]==' ')
                                ret+=15.0;
                            else
                                ret+=10.0;
                        }
                        if (numx==1)//we have a claim still
                        {
                            if (tiars[i][1]==' ')
                                ret+=2.0;
                            else
                                ret+=1.0;
                        }
                    }
                }
                else//see above!
                {
                    if (numo==0&&numx==2)
                        ret-=0.50;
                    else if (numo==0&&numx==1)
                        ret-=(tiars[i][1]=='X'?5.0:15.0);
                    else if (numx==0)
                    {
                        if (numo==2)
                        {
                            if (tiars[i][1]==' ')
                                ret+=15.0;
                            else
                                ret+=10.0;
                        }
                        if (numo==1)
                        {
                            if (tiars[i][1]==' ')
                                ret+=2.0;
                            else
                                ret+=1.0;
                        }
                    }
                }
            }
        }
        return ret;
    }
    virtual double negEvaluate(IGameState &gs)
    {
        isX=!isX;
        double ret=evaluate(gs);
        isX=!isX;
        return …
Labdabeta 182 Posting Pro in Training Featured Poster

The problem is on line 19 when you output an endl (newline) after the forward slash. Remove the endl and it should work fine.

Labdabeta 182 Posting Pro in Training Featured Poster

Sorry about my ambiguity. I think (but I am not sure) that the problem is in the evaluation function or in the implementation of my alpha beta algorithm. Here is an example of a game I played against it (I am 'O'):
X--
---
--- Perfect 1st move for Tic Tac Toe!

X--
-O-
--- A fair counter-attack that can ensure a tie

X--
-O-
--X Excellent play by the program, trying to set up a 'fork'

X--
OO-
--X I have to go in an edge to block the 'fork'


XX-
OO-
--X Why is X suddenly making such a stupid move? HERE IS THE PROBLEM!


XX-
OOO
--X I won... why wouldn't the program block me?

Labdabeta 182 Posting Pro in Training Featured Poster

I have an alpha beta interface and have implemented a tic tac toe class from it. For some reason my AI tends to occasionally make stupid moves (such as making a fork rather than blocking a 2 in a row) I was wondering if anybody can see where I went wrong:

StaticTicTacToe class:

class StaticTicTacToe:public IAlphaBetaPlayer
{
    private:
    bool isX;
    LABRandom r;
    public:
    StaticTicTacToe(bool isX):isX(isX),r(){}
    virtual double evaluate(IGameState &gs)
    {
        if (gs.ID()!=TICTACTOEID)
            return 0.0;
        char *s=(char*)gs.data;
        char tiars[8][3]={ {s[0],s[1],s[2]},{s[3],s[4],s[5]},{s[6],s[7],s[8]},
                           {s[0],s[4],s[8]},{s[2],s[4],s[6]},{s[0],s[3],s[6]},
                                {s[1],s[4],s[7]},{s[2],s[5],s[8]}};
        double ret=50.0;
        for (int i=0; i<8; i++)
        {
            //1st check for win
            if (tiars[i][0]==tiars[i][1]&&tiars[i][1]==tiars[i][2])
            {
                if (isX)
                {
                    if (tiars[i][0]=='X')
                        return 100.0;
                    else if (tiars[i][0]=='O')
                        return 0.0;
                }
                else
                {
                    if (tiars[i][0]=='O')
                        return 100.0;
                    else if (tiars[i][0]=='0')
                        return 0.0;
                }
            }
            else
            {
                int numx=0;
                int numo=0;
                if (tiars[i][0]=='X')
                    numx++;
                if (tiars[i][0]=='O')
                    numo++;
                if (tiars[i][1]=='X')
                    numx++;
                if (tiars[i][1]=='O')
                    numo++;
                if (tiars[i][2]=='X')
                    numx++;
                if (tiars[i][2]=='O')
                    numo++;
                if (isX)
                {
                    if ((s[0]=='O'||s[2]=='O'||s[6]=='O'||s[8]=='O')&&s[4]!='X')
                        return 0.01;//we will lose if they are smart...
                    if (numx==0&&numo==2)
                    {
                        return 0.01;
                    }
                    else if (numx==0&&numo==1)
                    {
                        ret-=(tiars[i][1]=='O'?1.0:3.0);
                    }
                    else if (numo==0)
                    {
                        if (numx==2)
                        {
                            if (tiars[i][1]==' ')
                                ret+=5.0;
                            else
                                ret+=2.0;
                        }
                        if (numx==1)
                        {
                            if (tiars[i][1]==' ')
                                ret+=2.0;
                            else
                                ret+=1.0;
                        }
                    }
                }
                else
                {
                    if ((s[0]=='X'||s[2]=='X'||s[6]=='X'||s[8]=='X')&&s[4]!='O')
                        return 0.01;//we will lose if they are smart...
                    if (numo==0&&numx==2)
                    {
                        return 0.01;
                    }
                    else if (numo==0&&numx==1)
                    {
                        ret-=(tiars[i][1]=='X'?1.0:3.0);
                    }
                    else if (numx==0)
                    {
                        if (numo==2)
                        {
                            if (tiars[i][1]==' ')
                                ret+=5.0;
                            else
                                ret+=2.0;
                        }
                        if (numo==1)
                        {
                            if (tiars[i][1]==' ')
                                ret+=2.0;
                            else
                                ret+=1.0;
                        }
                    }
                }
            } …