Department of Computer Science and Engineering, IIT Kanpur

CS245: Algorithms

Dr. R. K. Ghosh


Home | Notice Board | Instructor | TAs | Students | Assignments | Schedule | Lectures | Resources


Assignment 1
Deadline for submission :26 Jan 2003, Midnight
   The first assignment is to write a program(in C/C++) which will act as a player for a simple game to pick coins,in which the one who picks the last coin loses the game.

  The organization of coins is as shown in the figure.

  Rules of the game

Code requirements:

  •     The aim of your code is to act as a player. Only thing you have to do is plan your strategy for the game.
  •   A move can be specified as  a sequence of integers denoting the coin to be picked separated by comma.   eg:     1) If   you are to pick coins numbered 1, 2 and 4, then the move string will  be "1,2,4".                           2) If the other player picks the coins    7, 11 and 16 then the moves2 string will be "7,11,6 ".             

    Your program may look like the following skeleton code:

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

  

//Start

 


 //first read player number

   scanf("%d",&playrnum);

    switch(playernum){

/* Now if u r player 1 i.e playernum=1*/

  case 1 :  while(true)

            { // make your strategy

              printf("%s", move); 

            //move is a string consisting of coin numbers to be picked separated by commas

           // e.g: "124"

            scanf("%s",moves2);

         //read the strategies of other player

           }

         break;             

//if u r player 2

case 2 :  while(true)

          { //first move will be made by the other player               //first read his move

//             scanf("%s", moves2);

           //decide on u r strategy

           printf("%s",moves);

          }

         break;

}

/* end*/

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

Detection of malpractice:

     For each of the game conducted, the moves involved in it(of both the players) will be recorded, and any malpractice,(i.e, copying of programs) will be detected by an automated tool which will operate on this log file... So be aware of. copying of programs is dangerous!

Note

  • Your work is to develop a player program
  • Write the program in C/C++ only.
  • You will have to provide the executable file of your player program, games will be conducted (i.e your programs will be executed), in the presence of two players and TAs
  • Pleas put fflush(stdout); before scanf statement in your program

 


Home | Notice Board | Instructor | TAs | Students | Assignments | Schedule | Lectures | Resources


Page last updated 21 Jan, 2003 by Raghavendra Rao