示例#1
0
/*Checks for winning formations, declares the winner and ends the game. The program also makes a move on its own */
void singlePlayer()
{
 Player p1,p2;
 int r[6][7],c[6][7],ld[6][7],rd[6][7],i,j,res=0,n,win=0,ch,t,cp;
 char n1[20],n2[20];
 for(i=0;i<6;i++)
	{for(j=0;j<7;j++)
		r[i][j]=c[i][j]=ld[i][j]=rd[i][j]=0;}

 cout<<"\nEnter name: ";
 gets(p1.name);
 strcpy(n1,"You win!");
 strcpy(n2,"You lose!");
 while(res==0)
	{
	n=dispBoard(r,1);
	cp=coinPos(n,r);
	if (cp<0)
		{cout<<"\n\n\Please put coin in proper position";
		++res;
		break;}
	if(insRow(n,1,cp,r)==1)
		{drawround(n-1,-1,ray,WHITE);
		drawround(n-1,cp,ray,RED);
		delay(DEL);
		winDisp();
		outtextxy(xc,yc,n1);
		UpdatePStats(p1,'w');
		++res;
		break;}
	if(insCol(n,1,cp,c)==1)
		{drawround(n-1,-1,ray,WHITE);
		drawround(n-1,cp,ray,RED);
		delay(DEL);
		winDisp();
		outtextxy(xc,yc,n1);
		UpdatePStats(p1,'w');
		++res;
		break;}
	if(insLDia(n,1,cp,ld)==1)
		{drawround(n-1,-1,ray,WHITE);
		drawround(n-1,cp,ray,RED);
		delay(DEL);
		winDisp();
		outtextxy(xc,yc,n1);
		UpdatePStats(p1,'w');
		UpdatePStats(p1,'w');
		++res;
		break;}
	if(insRDia(n,1,cp,rd)==1)
		{drawround(n-1,-1,ray,WHITE);
		drawround(n-1,cp,ray,RED);
		delay(DEL);
		winDisp();
		outtextxy(xc,yc,n1);
		UpdatePStats(p1,'w');
		UpdatePStats(p1,'w');
		++res;
		break;}
	clrscr();
	dispBoard(r,0);
	if(winMove(r,c,ld,rd,-1)==1)
		{winDisp();
		outtextxy(xc,yc,n2);
		UpdatePStats(p1,'w');
		UpdatePStats(p1,'l');
		++res;
		break;}
	else if (defMove(r,c,ld,rd,-1)==0)
		{n=genMove(r,c,ld,rd,-1)+1;
		if (n==0)
			{drawround(n-1,cp,ray,GREEN);
			cout<<"\n\nDraw Match!";
			++res;
			break;}
		cp=coinPos(n,r);
		if(insRow(n,-1,cp,r)==-1)
			{drawround(n-1,cp,ray,GREEN);
			delay(DEL);
			winDisp();
			outtextxy(xc,yc,n2);
			UpdatePStats(p1,'l');
			++res;
			break;}
		if(insCol(n,-1,cp,c)==-1)
			{drawround(n-1,cp,ray,GREEN);
			winDisp();
			outtextxy(xc,yc,n2);
			UpdatePStats(p1,'l');
			++res;
			break;}
		if(insLDia(n,-1,cp,ld) ==-1)
			{drawround(n-1,cp,ray,GREEN);
			winDisp();
			outtextxy(xc,yc,n2);
			UpdatePStats(p1,'l');
			++res;
			break;}
		if(insRDia(n,-1,cp,rd)==-1)
			{drawround(n-1,cp,ray,GREEN);
			winDisp();
			outtextxy(xc,yc,n2);
			UpdatePStats(p1,'l');
			++res;
			break;}
		}
	clrscr();
	}
 getch();
 winDisp();
 outtextxy(xc,yc-10,"Thanks for ");
 outtextxy(xc,yc+10,"playing!");
}
示例#2
0
void loadStorePass(Seq<Instr>* instrs)
{
  Seq<Instr> newInstrs(instrs->numElems*2);

  // Put QPU number in a register
  Reg qpuId = freshReg();
  Reg qpuNum; qpuNum.tag = SPECIAL; qpuNum.regId = SPECIAL_QPU_NUM;
  newInstrs.append(genMove(qpuId, qpuNum));

  // Initialise strides
  genSetReadStride(&newInstrs, 0);
  genSetWriteStride(&newInstrs, 0);

  // Initialise load/store setup registers
  Reg vpmLoadSetup  = freshReg();
  Reg dmaLoadSetup  = freshReg();
  Reg dmaStoreSetup = freshReg();

  assignDMALoadSetup(&newInstrs, dmaLoadSetup, A, qpuId);
  assignDMAStoreSetup(&newInstrs, dmaStoreSetup, A, qpuId);
  assignVPMLoadSetup(&newInstrs, vpmLoadSetup, A, qpuId);

  genSetupVPMStore(&newInstrs, A, qpuId);

  // Elaborate LD1, LD3 and ST2 intermediate instructions
  Reg sp; sp.tag = SPECIAL;
  Reg src; src.tag = REG_A;
  for (int i = 0; i < instrs->numElems; i++) {
    Instr instr = instrs->elems[i];
    switch (instr.tag) {
      case LD1:
        sp.regId = SPECIAL_RD_SETUP;
        src.regId = RSV_READ_STRIDE;
        newInstrs.append(genMove(sp, src));
        newInstrs.append(genMove(sp, dmaLoadSetup));
        sp.regId = SPECIAL_DMA_LD_ADDR;
        newInstrs.append(genMove(sp, instr.LD1.addr));
        break;
      case LD3:
        sp.regId = SPECIAL_RD_SETUP;
        newInstrs.append(genMove(sp, vpmLoadSetup));
        for (int j = 0; j < 3; j++)
          newInstrs.append(nop());
        break;
      case ST2:
        sp.regId = SPECIAL_WR_SETUP;
        src.regId = RSV_WRITE_STRIDE;
        newInstrs.append(genMove(sp, src));
        newInstrs.append(genMove(sp, dmaStoreSetup));
        sp.regId = SPECIAL_DMA_ST_ADDR;
        newInstrs.append(genMove(sp, instr.ST2.addr));
        break;
      case RECV: {
        instr.tag = TMU0_TO_ACC4;
        newInstrs.append(instr);

        Instr move;
        move.tag                = ALU;
        move.ALU.setFlags       = false;
        move.ALU.cond.tag       = ALWAYS;
        move.ALU.dest           = instr.RECV.dest;
        move.ALU.srcA.tag       = REG;
        move.ALU.srcA.reg.tag   = ACC;
        move.ALU.srcA.reg.regId = 4;
        move.ALU.op             = A_BOR;
        move.ALU.srcB.tag       = REG;
        move.ALU.srcB.reg.tag   = ACC;
        move.ALU.srcB.reg.regId = 4;
        newInstrs.append(move);
        break;
      }
      default:
        newInstrs.append(instr);
        break;
    }
  }

  // Update original instruction sequence
  instrs->clear();
  for (int i = 0; i < newInstrs.numElems; i++)
    instrs->append(newInstrs.elems[i]);
}