Monday, August 31, 2009

Can't Wait for Attachment

yes .. I can't wait anymore ..left only about 1 week for my Industrial Training to commence at ST Electronics(Info-Software System) Pte Ltd .

so let me do some research about the company itself.

ST stands for Singapore Technologies .. The company has many departments which are :
- Large-Scale Systems Group
- Info Comm
- Satcom & Sensor Systems
- Info-Software Systems
- Training & Simulation Systems

STEE-InfoSoft is a Command, Control and Intelligence solutions provider. It provides superior defence simulation applications, homeland security systems and enterprise solutions to both civil and defence customers worldwide. Recently, STEE-InfoSoft has been awarded an S$8.2m contract by the Singapore Land Authority (SLA)to do some projects related to private and HDB properties registration system.

According to my Liason Officer, I am the only one who got posted to ST Electronics(Info-Software). I'm not sure whether there would be other interns from other institues or not. The ITP will be for about 6 weeks. The exiting part is that I'll be doing some programming stuff and they will teach me extra related stuff. Alhamdulillah I'll be able to do a job that I have passion for it.. Moreover , I am so grateful to be able to work for a reputable company when businesses are not doing so well.

That's all for today. ^_^

Tuesday, August 25, 2009

A Little Too Not Over You

I got this song from my sibling. It sounds good so I just went ahead and post the lyrics . The lyrics was taken from http://songlyrics.com ... Please enjoy

//lyrics begin
It never crossed my mind at all
It's what I tell myself
What we had is come and gone
You better offer someone else
It's for the best, I know it is
But I see you sometimes
I try to hide what I feel inside

And I turn around
You're with him now
I just can't figure it out

Tell me why you're so hard to forget
Don't remind me, I'm not over it
Tell me why I can't seem to face the truth
I'm just a little too not over you

Memories supposed to fade
What's wrong with my heart
Shake it off, let it go
Didn't think it'd be this hard
Should be strong, moving on
But I see you sometimes
I try to hide what I feel inside

And I turn around
You're with him now
I just can't figure it out

Tell me why you're so hard to forget
Don't remind me, I'm not over it
Tell me why I can't seem to face the truth
I'm just a little too not over you

Maybe I regret everything I said
No way to take it all back, yeah
Now I'm on my own, how I let you go
I'll never understand
I'll never understand
Yeah, oh no
Oh

Tell me why you're so hard to forget
Don't remind me, I'm not over it
Tell me why I can't seem to face the truth
I'm just a little too not over you

Tell me why you're so hard to forget
Don't remind me, I'm not over it
Tell me why I can't seem to face the truth
And I really don't know what to do
I'm just a little too not over you

Artist : David Archuletta
link : http://songlyrics.com

Sunday, August 23, 2009

Tic Tac Toe Artificial Intelligence

In this post I'm gonna include some of the codes I used personally to construct the computer AI.

It is mainly consist of if-else condition and it is not that relieable. If I were given a 2nd chance, I'll write a better AI codes that this one such as using switch/map/binary tree/etc .

If you are a student searching for an AI reference, I strongly recommend you to use your own creativity and understanding and please dont copy mine 100% . Because by copying my codes,
you'll not be able to gain the satisfaction feeling after you have comlpeted the codes.

Oh , one more thing! my AI is only about 70% intelligent I guess . I ensure you that you can't beat my AI if you are the 2nd player . Enjoy!

//-------AI codes begin ..............

if( (board[0]==human)&&(board[1]==human)&&(board[2]=='c') ) // blocks human moves 0 , 1 , 2 { move = 2 ; cout << "c" << endl ; return move ; } if( (board[0]==human)&&(board[2]==human)&&(board[1]=='b') ) // blocks human moves { move = 1 ; cout << "b" << endl ; return move ; } if( (board[2]==human)&&(board[1]==human)&&(board[0]=='a') ) // blocks human moves { move = 0 ; cout << "a" << endl ; return move ; }
if( (board[3]==human)&&(board[4]==human)&&(board[5]=='f') ) // blocks human moves 3 , 4 , 5 { move = 5 ; cout << "f" << endl ; return move ; }
if( (board[4]==human)&&(board[5]==human)&&(board[3]=='d') ) // blocks human moves { move = 3 ; cout << "d" << endl ; return move ; }
if( (board[6]==human)&&(board[7]==human)&&(board[8]=='i') ) // blocks human moves 6 , 7 , 8 { move = 8 ; cout << "i" << endl ; return move ; } if( (board[8]==human)&&(board[6]==human)&&(board[7]=='h') ) // blocks human moves { move = 7 ; cout << "h" << endl ; return move ; } if( (board[8]==human)&&(board[7]==human)&&(board[6]=='g') ) // blocks human moves { move = 6 ; cout << "g" << endl ; return move ; }
if( (board[0]==human)&&(board[3]==human)&&(board[6]=='g') ) // blocks human moves 0 , 3 , 6 { move = 6 ; cout << "g" << endl ; return move ; } if( (board[6]==human)&&(board[3]==human)&&(board[0]=='a') ) // blocks human moves { move = 0 ; cout << "a" << endl ; return move ; } if( (board[6]==human)&&(board[0]==human)&&(board[3]=='d') ) // blocks human moves { move = 3 ; cout << "d" << endl ; return move ; }
if( (board[1]==human)&&(board[4]==human)&&(board[7]=='h') ) // blocks human moves 1 , 4 , 7 { move = 7 ; cout << "h" << endl ; return move ; }
if( (board[4]==human)&&(board[7]==human)&&(board[1]=='b') ) // blocks human moves { move = 1 ; cout << "b" << endl ; return move ; }
if( (board[2]==human)&&(board[5]==human)&&(board[8]=='i') ) // blocks human moves 2 , 5 , 8 { move = 8 ; cout << "i" << endl ; return move ; } if( (board[8]==human)&&(board[2]==human)&&(board[5]=='f') ) // blocks human moves { move = 5 ; cout << "f" << endl ; return move ; } if( (board[5]==human)&&(board[8]==human)&&(board[2]=='c') ) // blocks human moves { move = 2 ; cout << "c" << endl ; return move ; }
if( (board[2]==human)&&(board[4]==human)&&(board[6]=='g') ) // blocks human moves 2 , 4 , 6 { move = 6 ; cout << "g" << endl ; return move ; }
if( (board[4]==human)&&(board[6]==human)&&(board[2]=='c') ) // blocks human moves { move = 2 ; cout << "c" << endl ; return move ; }
if(board[4] == 'e') { move = 4 ; cout << " e " << endl ; return move ; } if(board[0]=='a') { move = 0 ; cout << " a " << endl ; return move ; } if(board[2]=='c') { move = 2 ; cout << " c " << endl ; return move ; } if(board[6]=='f') { move = 6 ; cout << " g " << endl ; return move ; } if(board[8]=='i') { move = 8 ; cout << " i " << endl ; return move ; } if(board[1]=='b') { move = 1 ; cout << " b " << endl ; return move ; } if(board[3]=='d') { move = 3 ; cout << " d " << endl ; return move ; } if(board[5]=='f') { move = 5 ; cout << " f " << endl ; return move ; } if(board[7]=='h') { move = 7 ; cout << " h " << endl ; return move ; }

Wednesday, August 5, 2009

Tic Tac Toe Source

Whoa!! finally I managed to complete these humble source codes for Tic Tac Toe . It took me about 2 weeks to deal with the obstacles . Now , I understand what does a programmer feels when someone download/crack their files illegally . Please note that the codes shown below are not the ideal source codes for Tic Tac Toe . It is just a simpe version of the codes that my mind can understand . Please enjoy !

//===========codes starts here=======
#include
#include
#include

using namespace std;

char X = 'X' ;
char O = 'O' ;
char EMPTY = ' ' ;
char TIE = 'T' ;
char NO_ONE = 'N' ;
char playAgain ;


void instructions() ; //display instructions //
char askYesNo(string question) ; //ask whether you want to go 1st
char humanPiece() ; //determine human piece . returns 'x' / 'o' //
char opponent(char piece) ; //returns 'x'/'o' based on the previous choice //
void displayBoard(const vector &board) ; //display board on e screen //
int computerMove(vector board) ; //calculate computer's move,receives board n computer's piece,retutns com's move //
int isLegal(const vector board , int index) ; //
char winningCondition(vectorboard) ; //determines the game winner //




int main()

{
do
{
bool TrueFalse ;
char move , a ;
//int NUM_SQUARES = 9 ;
char alpha[] = { 'a','b','c','d','e','f','g','h','i' } ;
vector board(alpha , alpha+9) ;
int size = board.size() ;
vector :: iterator it ;
instructions() ; //
char human = humanPiece() ; //
char computer = opponent(human) ; //
char turn = X ;
displayBoard(board) ; //
char winner = NO_ONE ;
int legal = 0 ;
char check ;
int index ;
while(winner == NO_ONE ) //
{
if(turn == human)
{
do
{
cout << "Please enter an alphabet to choose that move : " ;
cin >> move ;


it = find(board.begin(), board.end(), move); //
index = it-board.begin() ; //replace it with this //
//cout << index ;
//cout << it ;
//cout << *it ;
legal = isLegal(board , index) ; // it replaced with index //

if(legal == 0)
{
cout << "invalid move , please enter the correct alphabet! " << endl ;
}
else
{
cout << "That move is valid" << endl ;
}
}while(legal != 1 ) ;
if(move == 'a') //
{
board.erase(board.begin()) ;
board.insert(board.begin() , 1 , human) ;
}
if(move == 'b') //
{
board.erase(board.begin()+1) ;
board.insert(board.begin()+1 , 1 , human) ;
}
if(move == 'c') //
{
board.erase(board.begin()+2) ;
board.insert(board.begin()+2 , 1 , human) ;
}
if(move == 'd') //
{
board.erase(board.begin()+3) ;
board.insert(board.begin()+3 , 1 , human) ;
}
if(move == 'e') //
{
board.erase(board.begin()+4) ;
board.insert(board.begin()+4 , 1 , human) ;
}
if(move == 'f') //
{
board.erase(board.begin()+5) ;
board.insert(board.begin()+5 , 1 , human) ;
}
if(move == 'g') //
{
board.erase(board.begin()+6) ;
board.insert(board.begin()+6 , 1 , human) ;
}
if(move == 'h') //
{
board.erase(board.begin()+7) ;
board.insert(board.begin()+7 , 1 , human) ;
}
if(move == 'i') //
{
board.erase(board.begin()+8) ;
board.insert(board.begin()+8 , 1 , human) ;
}
}
else
{
int ComMove = computerMove(board) ;
board.erase(board.begin()+ComMove) ;
board.insert(board.begin()+ComMove , 1 , computer) ;
}
displayBoard(board) ; //
turn = opponent(turn) ; //
check = winningCondition(board) ; //
//cout << "check is : " << check ;
//cout << "winner is : " << winner ;
winner = check ;
//cout << "winner is : " << winner ;

}
if((winner=='w') && (human == X)) // X condition for human
{
cout << "Congratulation human! you have won ... I'll defeat you next time!" << endl ;
}
if((winner=='w') && (computer==X)) //X for computer condition
{
cout << "I have defeated you human ... Is that all you got?! " << endl ;
}
if((winner=='c') && (human==O)) // O's condition for human
{
cout << "Congratulation human! you have won ... I'll defeat you next time!" << endl ;
}
if((winner=='c') && (computer==O))
{
cout << "I have defeated you human ... Is that all you got?! " << endl ;
}
if(winner == TIE)
{
cout << "Seems that our skills are equal .. Hence , its a draw! " << endl ;
}

cout << " do you want to play again ? " ;
cin >> playAgain ;


}while(playAgain == 'y') ;
return 0;

}

void instructions()
{
cout << "Welcome to the Tic Tac Toe game." << endl ;
cout << "You will be playing against the Computer (Com)." << endl ;
cout << "You need to make your move by entering character a-i" << endl ;
cout << "The number corresponds to the desired board postion as shown" << endl ;

cout << " a | b | c " << endl ;
cout << " --------- " << endl ;
cout << " d | e | f " << endl ;
cout << " --------- " << endl ;
cout << " g | h | i " << endl ;

cout << "Now, prepare yourself! The game is about to begin.." << endl<}

char askYesNo(string question)
{
char response ;
do
{
cout << question << " Yes (y) / No (n) : " << endl ;
cin >> response ;
}
while (response!='y' && response !='n') ;

return response ;
}

/*int askNumber(string question , int high , int low)
{
int number ;
do
{
cout << question << " (" << low << " - " << high << ") : " ;
cin >> number ;
}while(number>high || number
return number ;
}*/

char humanPiece()
{
char go_first = askYesNo("Do you want to move first ? ") ;
if(go_first == 'y')
{
cout << "Then , take the 1st move ! You'll be using X as your character piece" << endl ;
return X ;
}
else
{
cout << "Then, I'll go first" << endl ;
return O ;
}
}

char opponent(char piece)
{
if(piece == O)
return X ;
else
return O ;
}

void displayBoard(const vector&board)
{
cout << board[0] << " | " << board[1] << " | " << board[2] << endl ;
cout << "---------" << endl ;
cout << board[3] << " | " << board[4] << " | " << board[5] << endl ;
cout << "---------" << endl ;
cout << board[6] << " | " << board[7] << " | " << board[8] << endl ;
cout << endl ;
}

int isLegal(const vector board , int index)
{

//if((board[index]==X)&&(board[index]==O)) //('a'||'b'||'c'||'d'||'e'||'f'||'g'||'h'||'i'))
if(board[index] == 'a')
{
return 1 ;
}
if(board[index] == 'b')
{
return 1 ;
}
if(board[index] == 'c')
{
return 1 ;
}
if(board[index] == 'd')
{
return 1 ;
}
if(board[index] == 'e')
{
return 1 ;
}
if(board[index] == 'f')
{
return 1 ;
}
if(board[index] == 'g')
{
return 1 ;
}
if(board[index] == 'h')
{
return 1 ;
}
if(board[index] == 'i')
{
return 1 ;
}
else
{
return 0 ;
}
}

/*bool isLegal(int move , const vector &board)
{
return (board[move] != (X||O)) ;
}*/
int computerMove(vectorboard)
{
int move ;
cout << "I shall take " ;
//if no one can win
if(board[4] == 'e')
{
move = 4 ;
cout << " e " << endl ;
return move ;
}
if(board[2] == 'c')
{
move = 2 ;
cout << " c " << endl ;
return move ;
}
if(board[6] == 'g')
{
move = 6 ;
cout << " g " << endl ;
return move ;
}
if(board[8] == 'i')
{
move = 8 ;
cout << " c " << endl ;
return move ;
}
if(board[3] == 'd')
{
move = 3 ;
cout << " d " << endl ;
return move ;
}
if(board[4] == 'a')
{
move = 4 ;
cout << " a " << endl ;
return move ;
}
if(board[5] == 'f')
{
move = 5 ;
cout << " f " << endl ;
return move ;
}
if(board[1] == 'b')
{
move = 1 ;
cout << " b " << endl ;
return move ;
}
if(board[7] == 'h')
{
move = 7 ;
cout << " h " << endl ;
return move ;
}
}

char winningCondition(vector board)
{
if((board[0]==X)&&(board[1]==X)&&(board[2]==X))
{
return 'w' ; //someone has won
}
if((board[3]==X)&&(board[4]==X)&&(board[5]==X))
{
return 'w' ;
}
if((board[6]==X)&&(board[7]==X)&&(board[8]==X))
{
return 'w' ;
}
if((board[0]==X)&&(board[3]==X)&&(board[6]==X))
{
return 'w' ;
}
if((board[1]==X)&&(board[4]==X)&&(board[7]==X))
{
return 'w' ;
}
if((board[2]==X)&&(board[5]==X)&&(board[8]==X))
{
return 'w' ;
}
if((board[2]==X)&&(board[4]==X)&&(board[6]==X))
{
return 'w' ;
}
if((board[0]==X)&&(board[4]==X)&&(board[8]==X))
{
return 'w' ;
}

//O's winning condition return 2
if((board[0]==O)&&(board[1]==O)&&(board[2]==O))
{
return 'c' ; //O's user has won
}
if((board[3]==O)&&(board[4]==O)&&(board[5]==O))
{
return 'c' ;
}
if((board[6]==O)&&(board[7]==O)&&(board[8]==O))
{
return 'c' ;
}
if((board[0]==O)&&(board[3]==O)&&(board[6]==O))
{
return 'c' ;
}
if((board[1]==O)&&(board[4]==O)&&(board[7]==O))
{
return 'c' ;
}
if((board[2]==O)&&(board[5]==O)&&(board[8]==O))
{
return 'c' ;
}
if((board[2]==O)&&(board[4]==O)&&(board[6]==O))
{
return 'c' ;
}
if((board[0]==O)&&(board[4]==O)&&(board[8]==O))
{
return 'c' ;
}
//if( (board[0]==(X&&O)) , (board[1]==(X&&O)) , (board[2]==(X&&O)) , (board[3]==(X&&O)) , (board[4]==(X&&O)) , (board[5]==(X&&O)) , (board[6]==(X&&O)) , (board[7]==(X&&O)) , (board[8]==(X&&O)) )
//if(board[0],board[1],board[2],board[3],board[4],board[5],board[6],board[7],board[8]==(X||O))
if( ((board[0]==X)||(board[0]==O)) && ((board[1]==X)||(board[1]==O)) && ((board[2]==X)||board[2]==O) && ((board[3]==X)||(board[3]==O)) && ((board[4]==X)||(board[4]==O)) && ((board[5]==X)||(board[5]==O)) && ((board[6]==X)||(board[6]==O)) && ((board[7]==X)||(board[7]==O)) && ((board[8]==X)||(board[8]==O)) )
{
return TIE ;
}
else
{
return NO_ONE ; // indicate no one has won
}
}