neposlal by mi to nieto na maila? pretoze mi nejde ftp...dikeees
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Zobrazi prspevky MenuQuote from: Safyia on 26.05.2010, 18:20:20
ked das tu funkciu do if(frontIsClear) { bla bla } else { printf("daky error"); break; } musi to ukoncit.
Ak samozrejme nemas zle implementovane frontIsClear
#include <stdio.h>
#define MAX_WIDTH 20
#define MAX_HEIGHT 20
#define EMPTY 0
#define WALL -1
struct World{ /*vytvorili sme strukturu World*/
int width;
int height;
int data[MAX_HEIGHT][MAX_WIDTH];
};
struct World world; /*deklaracia premennej world typu World*/
enum Direction{ /*smery v ktorych sa moze karel pohybovat*/
EAST=0,
NORTH=90,
WEST=180,
SOUTH=270,
};
struct Robot{ /*vytvorili sme strukturu Robot*/
int x;
int y;
enum Direction direction;
int beepers;
};
struct Robot karel; /*deklaracia premennej karel typu Robot*/
//int world1[5][6] = { /*definicia karolovho sveta*/
/*{ 0, -1, -1, -1, 0, 0 },
{ 0, -1, 0, 0, -1, 0 },
{ 0, -1, -1, -1, 0, 0 },
{ 0, -1, 0, 0, -1, 0 },
{ 0, -1, 0, 0, -1, 0 }
};*/
//int newWorld[5][6] = { /*definicia karolovho sveta new*/
/* { 25, 26, 27, 28, 29, 30 },
{ 24, 23, 22, 21, 20, 19 },
{ 13, 14, 15, 16, 17, 18 },
{ 12, 11, 10, 9, 8, 7 },
{ 1, 2, 3, 4, 5, 6 }
};*/
void kresliKarla(){ /*vykresli karola podla toho na ktoru svetovu stranu je otoceny*/
if (karel.direction==EAST) printf("> ");
if (karel.direction==NORTH) printf("^ ");
if (karel.direction==WEST) printf("< ");
if (karel.direction==SOUTH) printf("v ");
}
void kresliMiestnost(int i,int j){ /*vykresli karolov svet*/
if(world.data[i][j]==EMPTY)printf(". ");
else if(world.data[i][j]==WALL)printf("# ");
else {
printf("%2d",world.data[i][j]);
}
}
void chyba(char*co){ /*definicia prikazu ktory sa urobi ak je chyba*/
printf("\n %s",co);
getchar();
exit(1);
}
void draw(){ /*definicia kreslenia*/
system("cls");
int i;
int j;
printf("x:%d y:%d beepersInBag: %d beepersOnGround: %d\n\n",
karel.x, karel.y, karel.beepers, world.data[karel.y][karel.x]);
for(i=0;i<world.height; i++){
for(j=0;j<world.width; j++){
if ((karel.x==j)&&(karel.y==i)){
kresliKarla();
}
else{
kresliMiestnost(i,j);
}
}
printf("\n");
}
printf("\n");
sleep(100);
}
/*void turnOnOld(){
karel.x=0;
karel.y=0;
karel.direction=0;
karel.beepers=0;
int i;
int j;
world.width = 6;
world.height = 5;
for(i=0; i<world.height; i++){
for(j=0; j<world.width; j++){
world.data[i][j]=newWorld[i][j];
}
}
draw();
}*/
void turnOn(char* meno){ /*funkcia aby vedela nacitat karolov svet zo suboru*/
char c;
int x,y,z,i,j;
FILE*f;
f=fopen(meno,"r");
if (f==0){
chyba("Subor sa nevie otvorit");
} /* podmienka ked f=0 tak skonci*/
fscanf(f,"%d %d %d %d %c %d \n",&world.width,&world.height,&karel.x,&karel.y,&c,&karel.beepers);
for (j=0; j<world.width; j++){
for (i=0; i<world.height; i++){
world.data[i][j]=0;
}
}
switch(c){ /*zisti podla premennej vlozenej do c urci kam je karel otoceny*/
case 'E' : karel.direction=EAST; break;
case 'N' : karel.direction=NORTH; break;
case 'W' : karel.direction=WEST; break;
case 'S' : karel.direction=SOUTH; break;
}
while(fscanf(f,"%c",&c)==1){
if(c=='W'){
fscanf(f,"%d %d\n",&x,&y);
world.data[y][x]=WALL;
}
else if(c=='B'){
fscanf(f,"%d %d %d\n",&x,&y,&z);
world.data[y][x]=z;
}
}
fclose(f);
draw();
}
void turnOff (char*meno) {
int i,j,a;
char c;
FILE*f=fopen("output.kw","w");
if(f==0){
printf("zle cislo");
}
switch (karel.direction){
case EAST: c = 'E'; break;
case NORTH: c = 'N'; break;
case WEST: c = 'W'; break;
case SOUTH: c = 'C'; break;
}
fprintf (f ,"%d %d %d %d %c %d \n", world.width, world.height, karel.x, karel.y, c, karel.beepers);
for (i=0; i<world.height; i++){
for (j=0; j<world.width; j++){
a=world.data[i][j];
if(a==WALL)
fprintf(f,"W %d %d\n",j,i);
if(a>0)
fprintf(f,"B %d %d %d\n",j,i,a);
}
}
fclose(f);
getchar();
exit(0);
}
int frontIsClear(){
int x=karel.x;
int y=karel.y;
switch(karel.direction){
case EAST : x++; break;
case NORTH: y--; break;
case WEST : x--; break;
case SOUTH: y++;break;
}
if((x<0)|| (y<0) || (x>=world.width) || (y>=world.height))
return 0;
if(world.data[x][y]==WALL)
return 0;
else
return 1;
}
int frontIsBlocked(){
return !frontIsClear();
}
int rightIsClear(){
int x=karel.x;
int y=karel.y;
switch(karel.direction){
case EAST : y++; break;
case NORTH: x++; break;
case WEST : y--; break;
case SOUTH: x--;break;
if((x<0)|| (y<0) || (x>world.width) || (y>world.height))
return 0;
if(world.data[x][y]==WALL)
return 0;
else
return 1;
}
}
int rightIsBlocked(){
return !rightIsClear();
}
int leftIsClear(){
int x=karel.x;
int y=karel.y;
switch(karel.direction){
case EAST : y--; break;
case NORTH: x--; break;
case WEST : y++; break;
case SOUTH: x++;break;
if((x<0)|| (y<0) || (x>world.width) || (y>world.height))
return 0;
if(world.data[x][y]==WALL)
return 0;
else
return 1;
}
}
int leftIsBlocked(){
return !leftIsClear();
}
int movek(){ /*int je tu kvoli premennej, pre return*/
int x=karel.x;
int y=karel.y;
switch(karel.direction){
case EAST : x++; break;
case NORTH: y--; break;
case WEST : x--; break;
case SOUTH: y++;break;
}
if((x<0)|| (y<0) || (x>world.width) || (y>world.height))
return;
if(world.data[y][x]==WALL)
return;
else {
karel.x=x;
karel.y=y;
}
draw();
printf("\n");
}
void turnLeft(){
karel.direction=karel.direction + 90;
if (karel.direction>270){
karel.direction=0;
}
draw();
printf("\n");
}
void turnRight(){
turnLeft();
turnLeft();
turnLeft();
}
void turnBack(){
turnLeft();
turnLeft();
}
int beepersPresent(){
if(world.data[karel.y][karel.x]>0)
return 1;
else
return 0;
}
int noBeepersPresent(){
return !beepersPresent();
}
int beepersInBag(){
if(karel.beepers>0)
return 1;
else
return 0;
}
int noBeepersInBag(){
return !beepersInBag();
}
int pickBeeper(){
if(world.data[karel.y][karel.x]>0) {
karel.beepers++;
world.data[karel.y][karel.x]--;
}
else {
chyba("Chyba Beeper");
}
draw();
sleep(100);
}
int putBeeper(){
if(karel.beepers>0){
karel.beepers--;
world.data[karel.y][karel.x]++;
}
else {
chyba("Neostatok Beeprov");
}
draw();
sleep(50);
}
int facingNorth(){
return karel.direction==NORTH;
}
int notFacingNorth(){
return karel.direction!=NORTH;
}
int facingSouth(){
return karel.direction==SOUTH;
}
int notFacingSouth(){
return karel.direction!=SOUTH;
}
int facingEast(){
return karel.direction==EAST;
}
int notFacingEast(){
return karel.direction!=EAST;
}
int facingWest(){
return karel.direction==WEST;
}
int notFacingWest(){
return karel.direction!=WEST;
}
int movek(){ /*int je tu kvoli premennej, pre return*/
int x=karel.x;
int y=karel.y;
switch(karel.direction){
case EAST : x++; break;
case NORTH: y--; break;
case WEST : x--; break;
case SOUTH: y++;break;
}
if((x<0)|| (y<0) || (x>world.width) || (y>world.height))
return;
if(world.data[y][x]==WALL)
return;
else {
karel.x=x;
karel.y=y;
}
draw();
printf("\n");
}
Quote from: Palike on 19.05.2010, 21:51:54ďakujem pekne...:-)) hadam to urobim dobreQuote from: potototamto on 19.05.2010, 21:01:25
no potom mi zase nerobi schody, iba vypise v riadku 12345...a do hora nic...
aby robilo iba po 6 :DDD...
krok=1;
b=2;
void stairs()
{
for(j=0;j<krok;j++)
{
for(a=1;a<b;a++)
{
putBeeper();
}
if (frontIsClear()) movek();
}
b++;
krok++;
}
ja som to upravil tak.. neviem ako to ide teraz tebe... nechapal som naco tam mas ten prvy cyklus :-$ a v tom dole... si tiez namiesto movek() daj if (frontIsClear()) move(); a este namiesto toho movekAll daj to iste len co ti nepocita tie kroky a potom na zaciatok si daj to movekAll nech ti spocita vysku sveta.. das nech sa vrati na zaciatok a potom namiesto toho cyklu to do 7 daj nech to robi po kolko.
Quote from: Palike on 19.05.2010, 21:36:05Quote from: potototamto on 19.05.2010, 21:17:30
uz mi to ide...vymenila som za inu zatvorku :-))) ďakujem
ale tu 7 si oprav.. lebo ked ti ucitel zvacsi svet tak to budes mat zle..
Quote from: Palike on 19.05.2010, 20:56:39Quote from: potototamto on 19.05.2010, 20:48:32
ako to opravym aby mi polozil beeper hned po otoceni....a nie az na druhom riadku..niekde vo funkcii dole???
funkcie este nemam spravne popisane :-DD
zadanie 11.
v stairs() mas tam ze sa pohne a da beeper... tak ked ho mas dole.. tak sa pohne a az potom da beeper takze je jasne ze tam bude jeden riadok volny.. skus to vymenit... ale aj tak to nemas podla mna dobre.. preco tam mas pokial krok neni 7?..
Quote from: Palike on 19.05.2010, 20:56:39Quote from: potototamto on 19.05.2010, 20:48:32
ako to opravym aby mi polozil beeper hned po otoceni....a nie az na druhom riadku..niekde vo funkcii dole???
funkcie este nemam spravne popisane :-DD
zadanie 11.
v stairs() mas tam ze sa pohne a da beeper... tak ked ho mas dole.. tak sa pohne a az potom da beeper takze je jasne ze tam bude jeden riadok volny.. skus to vymenit... ale aj tak to nemas podla mna dobre.. preco tam mas pokial krok neni 7?..
#include <stdio.h>
#include <stdlib.h>
#include "Library.h"
int i,pocet,j,krok,a,b;
pocet=0;
krok=0;
b=1;
//Karel ide az na koniec sveta
int movekAll(){
int kolko=0;
while(frontIsClear()) {
movek();
kolko=kolko+1;
}
return kolko;
}
//Karel ide spat dole
void dole(){
movekAll();
turnRight();
movek();
turnRight();
movekAll();
turnBack();
}
//Karel ide vzostupne (schody)
void stairs(){
for(i=1;i<pocet;i++)
pocet++;
for(j=0;j<krok;j++){
movek();
for(a=1;a<b;a++){
putBeeper();}
}
b++;
krok++;
}
int main(int argc, char *argv[])
{
/*if(argc!=2){
printf("malo parametrov");
getchar();
exit(1);}
turnOn(argv[1]); */
turnOn("world.kw"); //nacita svet
while(krok<7){
while(notFacingNorth()){ //zaciatocna poloha
turnLeft();
}
stairs(); //Karel robi schody, uklada zaradom Beepre
dole(); //Karel sa vracia do prveho riadku
}
turnRight();
system("PAUSE");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include "Library.h"
//ist s Karolom az pokial sa da
int movekAll(){
int kolko=0;
while(frontIsClear()) {
movek();
kolko=kolko+1;
}
return kolko;
}
//zide dole
void dole(){
movekAll();
turnRight();
movek();
turnRight();
movekAll();
turnBack();
}
int main(int argc, char *argv[])
{
/*if(argc!=2){
printf("malo parametrov");
getchar();
exit(1);}
turnOn(argv[1]); */
int i,pocet,j,krok,a,b;
pocet=0;
krok=0;
b=1;
turnOn("world.kw");
while(1){
while(notFacingNorth()){ //zaciatocna poloha , smer sever
turnLeft();
}
for(i=0;i<pocet;i++){
if(rightIsBlocked());
else{putBeeper();}
} //polozenie beepru
pocet++;
for(j=0;j<krok;j++){
movek();
for(a=1;a<b;a++){ //Karel uklada dalsie beepre vzostupne
putBeeper();
}
}
b++;
krok++;
dole(); //Karel sa vracia do prveho riadku
}
system("PAUSE");
return 0;
}
Quote from: bizzy on 13.05.2010, 02:36:13
nazdar, karla mam spraveneho, potrebujem ho iba trosku upravit, aby nebol presne ako kolegov, cize aby to nebol duplikat a k nemu dokumentaciu do zajtra vecera, kto by bol ochotny, piste spravu, alebo e-mail: bizzyy@pokec.sk
ODMENA podla dohody.
Quote from: Vikinger on 12.05.2010, 17:20:59Quote from: potototamto on 12.05.2010, 17:09:11
ale tu toho je :DDD..vďaka :DDD
cca ide tu o max 6 stran, ale je tam cely zdrojak takze prelistuj a najdeš :-) radšej nez budes cakat kym ti to sem dakto hodí