ELET2300 Assignment4 SubmityourprogramthroughBlackboard–Nolatesubmissions! Makesurethatyouuploadtherightfile(usually:main.cpp)!!!...

1 answer below »
Also includes notes for each step.


ELET2300 Assignment4 SubmityourprogramthroughBlackboard–Nolatesubmissions! Makesurethatyouuploadtherightfile(usually:main.cpp)!!! Inthisassignment,youwillimplementasimplifiedgameofDarainC++fortwo(human)players. 1.Firstbesuretounderstandhowthegameworks.Asummaryofthegamerulescanbefoundat theendofthisdocument.YoucanalsofindextrainformationatWikipedia: https://en.wikipedia.org/wiki/Dara_(game)andYouTube(https://youtu.be/4pEY9MUYibU). 2.Theoriginalgamestartswiththeplayerstakingturnstoplace12pieceseachona5x6square board(i.e.,the"drop"phase).Tosimplifytheverificationofyourprogram,theprogramwill readtheinitialboardsetupfromafileinsteadofaskingtheplayerstoenterthelocationsofthe initialpieces.Anexampleofthefilecontentsis: .XOXOX .XOOXX O.XOOX O.XO.O XOX.XO where"X","O"representthetokensofplayer1and2respectively.Thedot(.)representsan emptycell. Inyourprogramtheboardwillberepresentedasachararray.Donotusestrings.Implementthe filereadingandboardinitializationinaC++functionnamed"readBoard". 3.Yourprogrammustverifywhetherthisinitialconfigurationisavalidone,i.e.,makesurethat eachplayerhasexactly12piecesontheboardwithoutany3-pieceormorehorizontal/vertical row(seethegamerules). 4.Implementthefunction"displayBoard",whichasthenameimplies,willshowthecurrentstate ofthegameonthescreen. 5.WriteaC++loopinmain()toimplementthe"movephase"ofthegame.Theloopwill: A. Askplayer1forthelocationofthepiecethatshewantstomoveandthemovement direction('u','d','r','l'forup,downright,left).Ifthepieceattherequestedlocation belongstotheplayerANDthetargetcellisfree,thenexecutethemove.Otherwise,print anerrorandasktheusertoenteradifferentlocation/movedirection. B. Intheoriginalgame,avalidmovecannotformacolumn/rowof4equalpiecesormore andcannotputthelatestpiecebacktoitspreviouslocation.Thesetworulesareoptional forthisassignment,butyoucanimplementthemextracredit. C. Afteravalidmove,checkwhethera3-samepiecehorizonalorverticalrowwasformed. Ifso,asktheuserforthelocation,i.e.,therownumber,columnnumber,ofthepieceshe wantstocapture.Verifythatthelocationcontainsanopponent'spieceandthatisnot empty.Ifso,removethatpiece(makethatcellempty).Ifnot,askagaintheuserfora validlocation. D. Aftereachcapture,checkwhetherthegamehasended(i.e.,opponenthasnomore piecesontheboard).Ifso,printamessageannouncingso. E. Oncethegamehasended,askwhethertheywanttoplayagain.Ifso,restartthegameby re-readingtheinitialboardfromthefile(step2above).Ifnot,terminatetheprogram. DesignthemainloopinmodularformusingadditionalC++functions.Forexample,youcan implementa"gameover"functionthatcheckswhetherallopponent'spieceshasbeencaptured andthenmakecalltothatfunctionfrommain(). Notes: • YoumustuseonlytheC++instructionsthatwehavecoveredsofarinclass. • Theprogramthatyouturninmustbeyouroriginalandindividualwork.Whileyouareallowedto discusstheprogramassignmentsingeneraltermswithothers,youarenotallowedtosharedetailsof theactualsolution(s)orprogramcodewithanybodyexcepttheinstructor. • Turninginacopyofsomeoneelse'sprogram,evenacopywithextensivechangesmadetoit,or receivinganyunauthorizedassistanceisaveryseriousoffenseinthiscourse. • Anautomatedplagiarismcheckermayscanprogramsatanytimeduringthesemester. • Onlysubmityoursourcecode(.cpp).ThismustbedoneonorbeforetheduedatethroughBlackboard. Nolatesubmissions.Blackboardwillautomaticallyclosethesubmissionpagerightafterthedeadline. • Yourprogrammustincludecommentsexplainingyourstepsandmustbeproperlyformatted(see Program_Style_Guidelines.pdfinBlackboard). /∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗ELET2300
 ∗ProgrammingAssignment 
∗ *Compilertype(ifotherthenVisualC++) ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/ *CourtesyoftheMindResearchInstitute
Answered Same DayApr 12, 2021

Answer To: ELET2300 Assignment4 SubmityourprogramthroughBlackboard–Nolatesubmissions!...

Arun Shankar answered on Apr 15 2021
139 Votes
input.txt
.XOXOX
XXOOX.
O..XOX
O.XOXO
XOO.XO
main
main.cpp
main.cpp
/**************************
∗ Programming   Assignment  4
∗ Ariel Sifuentes 1441553
*
   Compiler    type    G++ C++17
**************************/
#include 
#include 
#include 
#include 
using namespace std;
void readBoard(char board[5][6])
{
  ifstream inFile;
  inFile.open("input.txt");
  if(!inFile)
  {
    cout<<"\nUnable to open the file. Exiting..";
    exit(0);
  }
  char x;
  int count;
  while(inFile>>x)
  {
    if(x=='.')
      x=' ';
    board[count/6][count%6] = x;
    ++count;
  }
  inFile.close();
}
void displayBoard(char board[5][6])
{
  for(int i=0;i<5;++i)
  {
    for(int j=0;j<6;++j)
      cout<<"| "<    cout<<"|"<  }
}
/* A helper function to check if the board has
3-piece horizontally or vertically */
bool check_consecutive(char board[5][6], char c)
{
  int count=0;
  for(int i=0;i<5;++i)
  {
    count = 0;
    for(int j=0;j<6;++j)
    {
      if(board[i][j]==c)
      {
        ++count;
        if(count==3)
          return true;
      } 
      else
        count = 0;
    } 
  } // end of outer for loop
  // Check vertical 
  for(int j=0;j<6;++j)
  {
    count = 0;
    for(int i=0;i<5;++i)
    {
      if(board[i][j]==c)
      {
        ++count;
        if(count==3)
          return true;
      } 
      else
        count = 0;
    }
  }
  return false;
}
bool check_valid(char board[5][6])
{
  int countX=0, countO=0;
  for(int i=0;i<5;++i)
    for(int j=0;j<6;++j)
      if(board[i][j]=='X')
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here