+ All Categories
Home > Documents > Suduko game

Suduko game

Date post: 03-Apr-2018
Category:
Upload: ajay-kumar-saklani
View: 220 times
Download: 0 times
Share this document with a friend

of 26

Transcript
  • 7/28/2019 Suduko game

    1/26

    TERM PAPER

    CSE101

    Topic: Suduko game

    DOA: 25-09-09

    DOS: 1-12-09

    Submitted to: Submitted by:

    Miss. Komal Mr. Piyush

    Deptt. Of Computer Science Roll. No. -A19

    Reg.No.-10904017

    Class-RB1902

  • 7/28/2019 Suduko game

    2/26

    Sudoku

    Introduction to Sudoku

    The name Sudoku is the Japanese abbreviation of a longer phrase meaning "the digits must

    remain single"; it is a trademark of puzzle publisher Nikoli Co. Ltd in Japan. Other Japanesepublishers refer to the puzzle as Nanpure (Number Place), which was its original title.

    The attraction of the puzzle is that the completion rules are simple, yet the line of reasoning

    required to reach the completion may be difficult. Sudoku is recommended by some teachers as

    an exercise in logical reasoning. The level of difficulty of the puzzles can be selected to suit the

    audience. The puzzles are often available free from published sources and also may be custom-

    generated using software.

    HISTORY

    Dell Magazines, the puzzle's originator, has been using numerals for Number Place in its

    magazines since they first published it in 1979. Numerals are used throughout this article. The

    puzzle was designed by Howard Garns, a retired architect and freelance puzzle constructor. In

    1989, Loadstar/ Softdisk Publishing published Digit Hunt on the Commodore 64, which was

    apparently the first home computer version of Sudoku. At least one publisher still uses that title.

    HOW TO PLAY SUDOKU?

    Sudoku requires no calculation or arithmetic skills. It is essentially a game of placing numbers

    in squares, using very simple rules of logic and deduction. It can be played by children and

    adults and the rules are simple to learn.

    SUDOKU OBJECTIVE

    The objective of the game is to fill all the blank squares in a game with the correct numbers.

    There are three very simple constraints to follow. In a 9 by 9 square Sudoku game:

    Every row of nine numbers must include all digits 1 through 9 in any order.

    Every column of 9 numbers must include all digits 1 through 9 in any order.

    Every 3 by 3 subsection of the 9 by 9 square must include all digits 1 through 9.

    Similarly, smaller Sudoku puzzles, such as the 4x4 puzzle, must have the numerals 1 through 4

    in each row, column and subsection. Larger Sudoku games (16 by 16) must have numerals 1

    through 16 in each row, column and region. The principles are the same whatever the size of

    the game.

    Every Sudoku games begin with a number of squares already filled in, and the difficulty of each

    game is largely a function of how many squares are filled in. The more squares that are known,

    the easier it is to figure out which numbers go in the open squares. As you fill in squares

    correctly, options for the remaining squares are narrowed and it becomes easier to fill them in.

  • 7/28/2019 Suduko game

    3/26

    The Sudoku games on SudokuDaily.net let you check your progress as you go, to help prevent

    going down a wrong path.

    #include#include#include

    #include#include#include

    extern short int user1=1,user2=0;extern short int array[8][8]={{0,0,0,0,0,0,0,0},

    {0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,2,2,0,0,0},{0,0,0,14,14,0,0,0},{0,0,0,0,0,0,0,0},

    {0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}};

    extern short int sp_color=0;extern short int current_yellow=2,current_green=2;extern short int color=0;extern short int color_back=0;extern short int write=0; executionextern short int user1_validity_checked=0, user2_validity_checked=1;extern short int gameover1=0,gameover2=0; extern short int total_boxes=0;filled or notextern short int print_box=0;profiles(to avoid printing of boxes while checking validity)

    extern short int validity_enabler=0;extern short int dir_array[8]={0,0,0,0,0,0,0,0}; //extern short intmax_dir=0; extern short int max_pixel_i=0; extern short intmax_pixel_j=0;extern short int max_value=0;void get_max(int i, int j);

    int select_box(int ,int );void delay();void backbox(int ,int );void update_array();void initial_setup();void sound1();

    void sound2();void setbox(int i,int j)

  • 7/28/2019 Suduko game

    4/26

    {int x,y,count=0;for(x=i-17; x

  • 7/28/2019 Suduko game

    5/26

    sound(i);delay(5);nosound();}

    }

    void movement(int *i, int *j,char ch){ //int x=*i,y=*j;

    // sound1();switch(ch){case 118:case 50:

    *j=*j+35;if(*j > (140+245))

    *j=140;break;case 100:case 52:

    *i=*i-35;if(*i < 70)*i=70+245;break;

    case 103:case 54: *i=*i+35;

    if(*i > (70+245))*i=70;

    break;

    case 114:case 56:

    *j=*j-35;if(*j < 140)*j=140+245;break;

    }

    }

    void whitebox(int i,int j){ int x,y;for(x=i-17+2; x

  • 7/28/2019 Suduko game

    6/26

    {if(x==i-17+2 || x==i-17+3 || x==i+18-2 || x==i+18-3 || y==j-17+2 ||y==j-17+3 || y==j+18-2 || y==j+18-3)

    putpixel(x,y,0);}print_box=1;

    fillbox(i,j,color_back);

    print_box=0;}

    void delay(){int x,y,z;for(x=0;x

  • 7/28/2019 Suduko game

    7/26

    }return(0);

    }

    int checkup(int x, int y)

    {if(y < 140){ write=0;return(0);

    }

    int s1,s2;s1=(x-70)/35;s2=(y-140)/35;

    int color1=array[s1][s2];;

    if(color1==BLACK)

    {write=0;return 0;

    }

    if(color1==color){

    return(0);}

    if(color1==sp_color){write=1;checkup(x,(y-35));

    }if(write){

    dir_array[1]=dir_array[1]+1;

    fillbox(x,y,color);fillbox(x,y+35, color);

    if(user1)color_back=YELLOW;if(user2)

    color_back=GREEN;}return(0);

    }

    int checkleft(int x, int y){if(x< 70){ write=0;return(0);

    }

    int s1,s2;s1=(x-70)/35;

  • 7/28/2019 Suduko game

    8/26

    s2=(y-140)/35;int color1=array[s1][s2]; if(color1==BLACK){write=0;return 0;

    }

    if(color1==color) {return(0);

    }if(color1==sp_color){write=1;checkleft((x-35),y); }

    if(write){

    dir_array[2]=dir_array[2]+1; fill

    fillbox(x,y,color);fillbox((x+35) ,y, color);if(user1)color_back=YELLOW; anything means)if(user2)color_back=GREEN;}return(0);

    }

    int checkright(int x, int y)

    {if(x > (70+245)) { write=0;return(0);

    }

    int s1,s2;s1=(x-70)/35;s2=(y-140)/35;

    int color1=array[s1][s2];

    if(color1==BLACK){

    write=0;return 0;}

    if(color1==color){

    return(0);}

    if(color1==sp_color){write=1;

    checkright((x+35),y);}

  • 7/28/2019 Suduko game

    9/26

    if(write){dir_array[3]=dir_array[3]+1;

    fillbox(x,y,color);fillbox((x-35) ,y, color);

    if(user1)color_back=YELLOW; anything means)if(user2)color_back=GREEN;}return(0);

    }

    int checkdia1(int x, int y){

    if((x > (70+245)) || ( y < (140))){ write=0;return(0);

    }

    int s1,s2;s1=(x-70)/35;s2=(y-140)/35;

    int color1=array[s1][s2];if(color1==BLACK){write=0;return 0;

    }

    )if(color1==color) {

    return(0);}

    if(color1==sp_color){write=1;checkdia1((x+35),(y-35}

    if(write){dir_array[4]=dir_array[4]+1;

    fillbox(x,y,color);fillbox((x-35) ,(y+35), color);

    if(user1)color_back=YELLOW; if(user2)color_back=GREEN;}return(0);

    }

  • 7/28/2019 Suduko game

    10/26

    int checkdia2(int x, int y){if((x > (70+245)) || ( y > (140+245))){ write=0;return(0);

    }

    int s1,s2;s1=(x-70)/35;s2=(y-140)/35;

    int color1=array[s1][s2];

    if(color1==BLACK){write=0;return 0;

    }

    if(color1==color) {return(0);}

    if(color1==sp_color){write=1;checkdia2((x+35),(y+35));}

    if(write){

    dir_array[5]=dir_array[5]+1;fill

    fillbox(x,y,color);fillbox((x-35) ,(y-35), color);

    if(user1)color_back=YELLOW;if(user2)color_back=GREEN;}return(0);

    }

    int checkdia3(int x, int y){if((x (140+245))) { write=0;return(0);

    }int s1,s2;s1=(x-70)/35;s2=(y-140)/35;

    int color1=array[s1][s2];

    if(color1==BLACK){write=0;

    return 0;}

  • 7/28/2019 Suduko game

    11/26

    )if(color1==color) {

    return(0);}

    if(color1==sp_color){write=1;checkdia3((x-35),(y+35));}

    if(write){dir_array[6]=dir_array[6]+1;

    fillbox(x,y,color);fillbox((x+35) ,(y-35), color);

    if(user1)

    {color_back=YELLOW; anything means)

    }if(user2){color_back=GREEN;}}return(0);

    }

    int checkdia4(int x, int y)

    {if((x

  • 7/28/2019 Suduko game

    12/26

    fillbox((x+35) ,(y+35), color);if(user1){ color_back=YELLOW;

    }if(user2)

    {color_back=GREEN;

    }

    }return(0);

    }

    void check_all_dir(int x, int y, int print){

    if(print==1)print_box=1;else print_box=0;write=0;update_array();checkdown(x,(y+35));checkup(x,(y-35));checkleft((x-35), y);checkright((x+35),y);checkdia1(x+35, y-35);checkdia2(x+35, y+35);checkdia3(x-35, y+35);checkdia4(x-35, y-35);

    }

    void update_array(){int i,j;

    current_yellow=0; current_green=0;for(i=0;i

  • 7/28/2019 Suduko game

    13/26

    for(i=70; i

  • 7/28/2019 Suduko game

    14/26

    int select_box(int i, int j){

    int x,y,t1,t2;char ch;

    int gdriver=DETECT,gmode=0;initgraph(&gdriver, &gmode, "c:\tc\bgi");

    initial_setup();gotoxy(0,0);gotoxy(52,13);printf("%d %d",current_yellow,current_green); initial scoregotoxy(0,0);

    while(1){ x=i;y=j;

    char ch;display_date();color_back=getpixel(i,j);update_array();whitebox(i,j);

    update_array();

    //TO CHECK USER 1 VALIDITY

    if((!user1_validity_checked) && user1)

    { user1_validity_checked=1;int color_back_retriver=color_back;

    if(user1_validity()){ user1=1;user2=0;gameover1=0;

    gotoxy(0,0);gotoxy(50,15);printf(" play1");gotoxy(0,0);

    gotoxy(64,15);

    printf(" ");gotoxy(0,0);}

    else{user1=0;user2=1;gameover1=1;user2_validity_checked=0;

    gotoxy(0,0);gotoxy(50,15);printf(" NO ");

    gotoxy(0,0);}

  • 7/28/2019 Suduko game

    15/26

    color_back=color_back_retriver;

    }

    if((!user2_validity_checked) && user2){

    int color_back_retriver=color_back;user2_validity_checked=1;if(user2_validity())

    {user2=1;user1=0;gameover2=0;gotoxy(0,0);gotoxy(64,15);printf(" play2");

    gotoxy(0,0);gotoxy(50,15);printf(" ");gotoxy(0,0);;}

    else{gameover2=1;user2=0;user1=1;user1_validity_checked=0;gotoxy(64,15);

    printf(" NO ");

    }color_back=color_back_retriver;

    }

    if((gameover1==1) && (gameover2==1) || total_boxes==64 ||current_yellow==0 || current_green==0)

    {update_array();gotoxy(1,1);

    if( current_yellow > current_green)printf("

    **************** USER1 IS THE

  • 7/28/2019 Suduko game

    16/26

    WINNER*************");

    else if(current_yellow

  • 7/28/2019 Suduko game

    17/26

    update_array();yellow_c=current_yellow;

    if(yellow_c != yellow_p){

    user1=0;user2=1;user2_validity_checked=0;sound1();gotoxy(52,13);printf("%d %d",current_yellow,current_green); //to

    display initial score

    }

    }

    if(ch==102 && user2) {int green_c, green_p;color=GREEN;sp_color=YELLOW;

    write=0;update_array();green_p=current_green;

    int s1,s2;s1=(x-70)/435;

    s2=(y-140)/35;if(array[s1][s2]==0) check_all_dir(x,y,1);

    update_array();green_c=current_green; if(green_c != green_p)

    {sound1();user2=0;user1=1;user1_validity_checked=0;gotoxy(52,13);printf("%d %d",current_yellow,current_green); }

    }

    movement(&i,&j,ch);backbox(x,y);}

    return(0);}

    void initial(){ print_box=1;

    fillbox(175,245,2);

    fillbox(210,245,2);fillbox(175,280,14);

  • 7/28/2019 Suduko game

    18/26

    fillbox(210,280,14);print_box=0;

    }

    void putbox(){

    for(int i=70;i

  • 7/28/2019 Suduko game

    19/26

    int single_player_game(){int gdriver=DETECT,gmode=0;initgraph(&gdriver, &gmode, "c:\tc\bgi");int i=70;int j=140;

    int x,y;initial_setup();gotoxy(0,0);gotoxy(52,13);printf("%d %d ",current_yellow,current_green); //to displayinitial scoregotoxy(0,0);

    while(1){ x=i;

    y=j;char ch;

    display_date();color_back=getpixel(i,j);update_array();whitebox(i,j);

    update_array();gotoxy(0,0);gotoxy(52,13);

    //TO CHECK USER 1 VALIDITY

    if((!user1_validity_checked) && user1)

    { user1_validity_checked=1;int color_back_retriver=color_back;if(user1_validity()){ user1=1;user2=0;gameover1=0;

    gotoxy(1,1); gotoxy(50,15);printf(" play1");gotoxy(1,1);gotoxy(64,15);printf(" ");gotoxy(1,1);

    }

    else{user1=0;user2=1;gameover1=1;user2_validity_checked=0;

    gotoxy(1,1); gotoxy(50,15);printf(" NO ");gotoxy(1,1);

    }color_back=color_back_retriver;

  • 7/28/2019 Suduko game

    20/26

    }

    ch=getch();if(ch==27) break;

    if(ch==13 && user1){ int yellow_p, yellow_c;

    color=YELLOW;sp_color=GREEN;write=0;

    update_array();yellow_p=current_yellow;

    int s1,s2;s1=(x-70)/35;s2=(y-140)/35;if(array[s1][s2]==0)

    check_all_dir(x,y,1);

    update_array();yellow_c=current_yellow;

    if(yellow_c != yellow_p) only switch to yser2{

    sound1();user1=0;user2=1;user2_validity_checked=0;

    gotoxy(52,13);printf("%d %d

    ",current_yellow,current_green);printf("%d %d ",current_yellow,current_green);}

    }

    gotoxy(0,0);gotoxy(52,13);

    if((!user2_validity_checked) && user2){int color_back_retriver=color_back;

    user2_validity_checked=1;if(user2_validity())

    {user2=1;user1=0;gameover2=0;

    //to display validity below score boardgotoxy(64,15);printf("computer");gotoxy(50,15);

    printf(" ");

  • 7/28/2019 Suduko game

    21/26

    }

    else{gameover2=1;user2=0;

    user1=1;user1_validity_checked=0;

    gotoxy(64,15);printf(" NO ");

    }color_back=color_back_retriver;

    }

    if((gameover1==1) && (gameover2==1) || total_boxes==64 ||current_yellow==0 || current_green==0)

    {

    gotoxy(1,1);update_array();if( current_yellow > current_green)printf("

    **************** USER1 IS THEWINNER*************");

    else if(current_yellow

  • 7/28/2019 Suduko game

    22/26

    ************ M A T C H IS D RA W *************");

    gotoxy(1,1);printf("

    **************** G A M E O V E

    R*************");return(0);

    }

    if(user2){int green_c, green_p;

    int m,n;int color_back_retriver=color_back;

    color=GREEN;sp_color=YELLOW;max_value=0;

    write=0;update_array();

    for(int t=0;t

  • 7/28/2019 Suduko game

    23/26

    a=70+(m*35);b=140+(n*35);

    for(int t=0;t

  • 7/28/2019 Suduko game

    24/26

    and another Yellow box,that yellow box belongs to ");printf("upward,downward,leftside,

    rightside or any diagonal directionto your cursor.

    ");printf(" Same thing to user2 also, he got to play with Greenboxe's.

    ");printf("USER1 CONTROL KEYS:");printf("*******************");printf("The directional keys in num-pad and enter key in num-pad

    ");printf("USER2 CONTROL KEYS:");printf("*********************");printf(" D = left movementR = up-ward movementG = right movementV

    = down-ward movementF = Enter key

    ");

    getch();clrscr();}

    int preamble(){ int options;

    while(1){

    printf("

    SELECT YOUR OPTION

    "); printf("******************");

    printf(" 1. Instructions

    2. Single playergame(player2=computer)

    ");printf(" 3. Two player game

    ");printf(" 4. Exit from the game

    ");scanf("%d",&options);

  • 7/28/2019 Suduko game

    25/26

    clrscr();switch(options){case 1:display_instr(); break;case 2: single_player_game(); return(0);case 3:select_box(70,140); return(0);

    case 4:exit(0);default: printf("please enter the valid choice

    ");

    }}

    }

    void initial_setup(){

    outline(RED);putbox();initial();int x,y;gotoxy(50,9);printf("user1 user2");gotoxy(0,0);

    for(x=400; x

  • 7/28/2019 Suduko game

    26/26

    printf("GAME OVER");

    return 0;}


Recommended