public virtual void Llena(Colores[] c) { if(c==null)throw new ArgumentNullException("Imposible rellenar arreglo nulo"); if(c.Length>a.Length)throw new Exception(); for(int i=0;i<c.Length;i++) c[i]=a[i]; }
public virtual void LlenaAleatoriamente(Colores[] c,int hasta) { int x=0; if(c==null)throw new ArgumentNullException("Imposible rellenar arreglo nulo"); if(c.Length>a.Length)throw new Exception(); for(int i=0;i<c.Length;i++){ x=new Random().Next(hasta+1); c[i]=a[x];} }
public virtual void LlenaAleatoriamenteSinRep(Colores[] c,int hasta) { int[] arr=new int[c.Length]; int mark=0; int x=0; for(int i=0;i<c.Length;i++) { do { x=new Random().Next(hasta); }while(this.Pertenece(arr,x,mark)); arr[mark++]=x; c[i]=a[x]; } }
public Juego1(int posibles,int reales,Paleta p,int largo) { if(posibles<6) posibles=6; else if(posibles>12) posibles=12; if(reales<4) reales=4; else if(reales>8)reales=8; colpos=new Colores[posibles]; colres=new Colores[largo][]; puntos=new Colores[largo][]; for(int i=0;i<largo;i++){ colres[i]=new Colores[reales]; puntos[i]=new Colores[reales]; } answer=new Colores[reales]; p.Llena(colpos); p.LlenaAleatoriamenteSinRep(answer,colpos.Length-1); altura=largo-1; }
public virtual int EvaluaCol(Colores[] resp) { bool[] marcans=new bool[resp.Length]; bool[] marcresp=new bool[resp.Length]; int inc=0;int negros=0; int x=new Random().Next(resp.Length); for(int i=0;i<resp.Length;i++) { if(this.answer[(x+i)%resp.Length]==resp[(x+i)%resp.Length]) { marcans[(x+i)%resp.Length]=true; marcresp[(x+i)%resp.Length]=true; this.puntos[this.altura][inc++]=new Colores("negro",Color.Black); negros++; } } if(negros==resp.Length)return 1; for(int i=0;i<resp.Length;i++) { if(!marcans[(x+i)%resp.Length]) { for(int j=0;j<resp.Length;j++) { if(this.answer[(x+i)%resp.Length]==resp[(x+j)%resp.Length] && !marcresp[(x+j)%resp.Length]) { marcans[(x+i)%resp.Length]=true; marcresp[(x+j)%resp.Length]=true; this.puntos[this.altura][inc++]=new Colores("blanco",Color.White); break; } } } } this.colres[altura]=resp; this.altura--; if(altura!=-1)return 0; return -1; }
private void InicColor() { a[0]=new Colores("rojo",Color.Red); a[1]=new Colores("azul",Color.Blue); a[2]=new Colores("verde",Color.Green); a[3]=new Colores("rosado",Color.Pink); a[4]=new Colores("amarillo",Color.Yellow); a[5]=new Colores("violeta",Color.Purple); a[6]=new Colores("verdeclaro",Color.LightGreen); a[7]=new Colores("azulclaro",Color.LightBlue); a[8]=new Colores("carmelita",Color.Brown); a[9]=new Colores("naranja",Color.Orange); a[10]=new Colores("negro",Color.Black); a[11]=new Colores("blanco",Color.White); }