NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <stdio.h>
#include <string.h>

unsigned short b3tous( char b3[10] );
void b3fromus( char b3[10], unsigned short us );
void boardtob3( char b3[10], char board[60] );
void boardfromb3( char board[60], char b3[10] );
char winner( unsigned short us );
unsigned short next ( unsigned short us, char pos );
char get_move( char b3[10] );
char get_turn( char b3[10] );

int main() {

/*
unsigned short a7a;
char a7A[10] = "012012011";
printf("Hello Worldn");

a7a = b3tous( a7A );

printf("n%hu", a7a);

b3fromus( a7A, 3784);

printf("n%s", a7A);



char lol[10] ="220011220" ;
char bb[60] ;

boardfromb3( bb, lol );
printf("%sn", bb);

unsigned short a7 = 19300;
char AA = 'Z';
AA = winner( a7 );

printf("nValue is %c", AA);

unsigned short a7 = 1621;
char gg = '2';
unsigned short ll;


ll = next ( a7, gg );

char lol[60];
char B3[10];
unsigned short a7 = 12302;
char da2at, alol;

b3fromus( B3, a7 );

da2at = get_move( B3 );
alol = get_turn( B3 );

printf("%c %c", da2at, alol); */
return 0;
}


unsigned short b3tous( char b3[10] ){

unsigned short sum = 0;
unsigned short multValue1 = 4;
unsigned short multValue2 = 1;

int i = 8;
while (i>=0)
{
if (b3[i] == '0'){
multValue1 = 0;
}

else if (b3[i] == '1'){
multValue1 = 1;
}

else if (b3[i] == '2'){
multValue1 = 2;
}

sum = sum + (multValue1 * multValue2);

i--; multValue2 = multValue2 * 3;
}

return sum;
}

void b3fromus( char b3[10], unsigned short us )
{

int base[9] = {6561,2187,729,243,81,27,9,3,1};
int digit[9] = {100000000,10000000,1000000,100000,10000,1000,100,10,1};
int num = 0;
int i=0;
int j=0;
int x=10;

for(i=0;i<2;i++){
if((us %3)!= 0)
{
us = us - 1;
num = num +1;
}
}

while(us!= 0)
{
for(i=0;i<=16;i++)
{
for(j=0;j<8;j++)
{
if(us>= base[j])
{
us = us - base[j];
num = num + digit[j];
break;
}
}
}
}

if(num%10 == 0)
b3[8]='0';
else if(num%10 == 1)
b3[8]='1';
else if(num%10 == 2)
b3[8]='2';

for(i=7;i>=0;i--)
{
if(num%(x*10) - num%x == 0)
b3[i] = '0';

else if(num%(x*10) - num%x == 1*x)
b3[i] = '1';

else if(num%(x*10) - num%x == 2*x)
b3[i] = '2';

x = x*10;
}
}

void boardtob3( char b3[10], char board[60] )
{

if(board[1] == 'X' )
b3[0] = '2';
if(board[5] == 'X' )
b3[1] = '2';
if(board[9] == 'X' )
b3[2] = '2';
if(board[25] == 'X' )
b3[3] = '2';
if(board[29] == 'X' )
b3[4] = '2';
if(board[33] == 'X' )
b3[5] = '2';
if(board[49] == 'X' )
b3[6] = '2';
if(board[53] == 'X' )
b3[7] = '2';
if(board[57] == 'X' )
b3[8] = '2';

if(board[1] == 'O' )
b3[0] = '1';
if(board[5] == 'O' )
b3[1] = '1';
if(board[9] == 'O' )
b3[2] = '1';
if(board[25] == 'O' )
b3[3] = '1';
if(board[29] == 'O' )
b3[4] = '1';
if(board[33] == 'O' )
b3[5] = '1';
if(board[49] == 'O' )
b3[6] = '1';
if(board[53] == 'O' )
b3[7] = '1';
if(board[57] == 'O' )
b3[8] = '1';

if(board[1] == ' ' )
b3[0] = '0';
if(board[5] == ' ' )
b3[1] = '0';
if(board[9] == ' ' )
b3[2] = '0';
if(board[25] == ' ' )
b3[3] = '0';
if(board[29] == ' ' )
b3[4] = '0';
if(board[33] == ' ' )
b3[5] = '0';
if(board[49] == ' ' )
b3[6] = '0';
if(board[53] == ' ' )
b3[7] = '0';
if(board[57] == ' ' )
b3[8] = '0';
}

void boardfromb3( char board[60], char b3[10] )
{
char boardExtra[60] = " | | n---+---+---n | | n---+---+---n | | ";

strcpy(board,boardExtra);

if(b3[0] == '2' )
board[1] = 'X';
if(b3[1] == '2' )
board[5] = 'X';
if(b3[2] == '2' )
board[9] = 'X';
if(b3[3] == '2' )
board[25] = 'X';
if(b3[4] == '2' )
board[29] = 'X';
if(b3[5] == '2' )
board[33] = 'X';
if(b3[6] == '2' )
board[49] = 'X';
if(b3[7] == '2' )
board[53] = 'X';
if(b3[8] == '2' )
board[57] = 'X';

if(b3[0] == '1' )
board[1] = 'O';
if(b3[1] == '1' )
board[5] = 'O';
if(b3[2] == '1' )
board[9] = 'O';
if(b3[3] == '1' )
board[25] = 'O';
if(b3[4] == '1' )
board[29] = 'O';
if(b3[5] == '1' )
board[33] = 'O';
if(b3[6] == '1' )
board[49] = 'O';
if(b3[7] == '1' )
board[53] = 'O';
if(b3[8] == '1' )
board[57] = 'O';

if(b3[0] == '0' )
board[1] = ' ';
if(b3[1] == '0' )
board[5] = ' ';
if(b3[2] == '0' )
board[9] = ' ';
if(b3[3] == '0' )
board[25] = ' ';
if(b3[4] == '0' )
board[29] = ' ';
if(b3[5] == '0' )
board[33] = ' ';
if(b3[6] == '0' )
board[49] = ' ';
if(b3[7] == '0' )
board[53] = ' ';
if(b3[8] == '0' )
board[57] = ' ';
}

char winner( unsigned short us )
{

int i;
int tie = 0;
char re;

char B3[10];
b3fromus( B3, us );


for(i=0;i<9;i++)
{
if(B3[i] == '0')
tie++;
}
if (tie == 0)
re = '0';


if((B3[0] != '0') && (B3[0] == B3[1]) && (B3[1] == B3[2]))
{
if(B3[0] == '2')
re = '2';
if(B3[0] == '1')
re = '1';
}

if((B3[3] != '0') && (B3[3] == B3[4]) && (B3[4] == B3[5]))
{
if(B3[3] == '2')
re = '2';
if(B3[3] == '1')
re = '1';
}

if((B3[6] != '0') && (B3[6] == B3[7]) && (B3[7] == B3[8]))
{
if(B3[6] == '2')
re = '2';
if(B3[6] == '1')
re = '1';
}




if((B3[0] != '0') && (B3[0] == B3[3]) && (B3[3] == B3[6]))
{
if(B3[0] == '2')
re = '2';
if(B3[0] == '1')
re = '1';
}

if((B3[1] != '0') && (B3[1] == B3[4]) && (B3[4] == B3[7]))
{
if(B3[1] == '2')
re = '2';
if(B3[1] == '1')
re = '1';
}

if((B3[2] != '0') && (B3[2] == B3[5]) && (B3[5] == B3[8]))
{
if(B3[2] == '2')
re = '2';
if(B3[2] == '1')
re = '1';
}




if((B3[0] != '0') && (B3[0] == B3[4]) && (B3[4] == B3[8]))
{
if(B3[0] == '2')
re = '2';
if(B3[0] == '1')
re = '1';
}

if((B3[2] != '0') && (B3[2] == B3[4]) && (B3[4] == B3[6]))
{
if(B3[2] == '2')
re = '2';
if(B3[2] == '1')
re = '1';
}

return re;
}

unsigned short next ( unsigned short us, char pos )
{

unsigned short next;

int Pos;
int moveNum = 1;
int i;

char B3[10];
b3fromus( B3, us );

if(pos == '0')
Pos = 0;
if(pos == '1')
Pos = 1;
if(pos == '2')
Pos = 2;
if(pos == '3')
Pos = 3;
if(pos == '4')
Pos = 4;
if(pos == '5')
Pos = 5;
if(pos == '6')
Pos = 6;
if(pos == '7')
Pos = 7;
if(pos == '8')
Pos = 8;

if(B3[Pos] != '0' )
next = 0;

else
{
for(i=0;i<9;i++)
{
if(B3[i] != '0')
moveNum++;
}

if((moveNum % 2) == 0)
B3[Pos] = '1';

else
B3[Pos] = '2';

}

next = b3tous(B3);
return next;

}

char get_move( char b3[10] )
{

int i;
int moveNum = 0;
char re;

for(i=0;i<9;i++)
{
if(b3[i] != '0')
moveNum++;
}

if(moveNum == 0)
re = '0';
if(moveNum == 1)
re = '1';
if(moveNum == 2)
re = '2';
if(moveNum == 3)
re = '3';
if(moveNum == 4)
re = '4';
if(moveNum == 5)
re = '5';
if(moveNum == 6)
re = '6';
if(moveNum == 7)
re = '7';
if(moveNum == 8)
re = '8';

return re;
}

char get_turn( char b3[10] ){

int i;
int moveNum = 1;
char re;

for(i=0;i<9;i++)
{
if(b3[i] != '0')
moveNum++;
}

if((moveNum % 2) == 0)
re = '1';
else
re = '2';

return re;
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.