Začne behať a keď vezme 4 beepre ide domov. Potom zas začne behať, ale už vezme všetky beepre vo svete a pritom by sa mal po 4 sa zase vrátiť domov.
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� pr�spevky Menu
int main(){
int beep = 0;
turnOn("world.txt");
draw();
while (frontIsClear()){ // cyklus, aby sie K stale dopredu
movek();
beep:
while (beepersPresent()){
pickBeeper();
beep++;
if (beep == 4) domov();}
if (frontIsBlocked() && facingSouth()){ //ak narazi na stenu a je otoceny dole
turnLeft();
if (frontIsBlocked() && rightIsBlocked()){ //ak dojde do rohu sveta
turnLeft();
turnLeft();
while (frontIsClear())
movek();
while (frontIsClear()){
movek();
while (frontIsBlocked())
if (beepersInBag())
putBeeper();
else goto koniec;
}
}
else movek();
if (rightIsClear())
okoloDole(); // obide stenu vo vnutri sveta
else turnLeft();
}
if (frontIsBlocked() && facingNorth()){ //ak narazi na stenu a je otoceny hore
turnRight();
if (frontIsBlocked() && leftIsBlocked()){ //ak dojde to rohu sveta
turnLeft();
turnLeft();
while (frontIsClear())
movek();
while (frontIsBlocked())
if (beepersInBag())
putBeeper();
else goto koniec;
}
else movek();
if (leftIsClear())
okoloHore(); //obide stenu
else turnRight();
}
}
koniec:
system("PAUSE");
return 0;
}
while (beepersPresent()){
pickBeeper();
beep++;
if (beep == 4) domov();}
Quote from: miro2141 on 09.05.2010, 22:39:58niekde v library.c by si mal mať
Caute ChalaniChcem sa opytat ohladom 12. zadania.... Po tom čo prejde Karol ma nechat Beeper.... no to je ten problem ze nema nechat cislo ale # . Ako to mam urobit? Co mam prepisat v definicii??Diky
if (svet.world[x][y] > 0) printf("%d", svet.world[x][y]);
if (svet.world[x][y] > 0) printf("#");
Quote from: luky on 09.05.2010, 17:52:42Quote from: Shwollo on 09.05.2010, 17:26:00
prečo mi to neche fungovať? ono sa to vôbec nereaguje na funkciu "domov". Chcel som spraviť, že keď vezme 4 beepre tak pôjde "domov".
while (beepersPresent())
pickBeeper();
beep++;
if (beep == 4)
domov();
zložené zátvorky!
while (beepersPresent()){
pickBeeper();
beep++;
if (beep == 4)
domov();}
int beep = 0;
turnOn("world.txt");
draw();
while (frontIsClear()){ // cyklus, aby sie K stale dopredu
movek();
while (beepersPresent()){
pickBeeper();
beep++;
if (beep == 4)
domov();
}
else{
if (frontIsBlocked() && facingSouth()){ //ak narazi na stenu a je otoceny dole
turnLeft();
if (frontIsBlocked() && rightIsBlocked()){ //ak dojde do rohu sveta
turnLeft();
turnLeft();
while (frontIsClear())
movek();
if (frontIsBlocked()){
turnRight();
while (frontIsClear()){
movek();
while (frontIsBlocked()){
if (beepersInBag())
putBeeper();
else goto koniec;
}
}
}
}
else movek();
void turnOff(){
int y, x;
FILE *fp;
char dir;
fp = fopen( "output.kw", "w" );
{
if (karel.direction == 'N') dir = 'N';
if (karel.direction == 'S') dir = 'S';
if (karel.direction == 'W') dir = 'W';
if (karel.direction == 'E') dir = 'E';
}
fprintf(fp, "%d %d %d %d %c %d\n", svet.width, svet.height, karel.x, karel.y, dir, karel.beepers);
char dir;
fscanf (f, "%d %d %d %d %c %d", &svet.width, &svet.height, &karel.x, &karel.y, &dir, &karel.beepers);
karel.x--;
karel.y--;
if (dir == 'S') karel.direction = S;
.
.
.
typedef struct {
int x, y, direction, beepers;
}ROBOT;
ROBOT karel;
void turnOff(){
int y, x;
FILE *fp;
char dir;
fp = fopen( "output.kw", "w" );
{
if (karel.direction == 'N') dir = 'N';
if (karel.direction == 'S') dir = 'S';
if (karel.direction == 'W') dir = 'W';
if (karel.direction == 'E') dir = 'E';
}
fprintf(fp, "%d %d %d %d %c %d\n", svet.width, svet.height, karel.x, karel.y, dir, karel.beepers);
#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0
int width,height;
int world[MAX_HEIGHT][MAX_WIDTH];
typedef struct {
int x,y,direction, beepers;
}ROBOT;
ROBOT karel;
typedef enum {
E, N, W, S
}direction;
typedef enum {
FALSE, TRUE
}Boolean;
void turnOn(char *path){
path = fopen ("world.txt", "r");
fscanf (path, "%d %d %d %d %c %d", &width, &height, &karel.x, &karel.y, &karel.direction, &karel.beepers);
int x,y;
for(x=0; x<height; x++){
for(y=0; y<width; y++)
world[width][height];
}
}
void draw()
{
if (width > 20 || height > 20) { printf ("chyba, maximalne rozmery svera su 20x20, \npokracujte stlacenim klavesy enter"); getchar(); exit(1); }
else {
system("cls");
printf("pozicia: x:%d y:%d \n",karel.x, karel.y);
printf("orientacia: ");
if (karel.direction == S) printf("juh \n");
if (karel.direction == N) printf("sever \n");
if (karel.direction == W) printf("zapad \n");
if (karel.direction == E) printf("vychod\n");
printf("pocet beeprov v batohu: %d\n", karel.beepers);
printf("tu je %d beeprov\n", world[karel.x][karel.y]);
printf("ma beepre? %d\nje tu beeper? %d\n", beepersInBag(), beepersPresent());
printf("orientacia %c \n \nfrontIsblocked? %d \n", karel.direction, frontIsBlocked());
printf("frontIsClear? %d\nrightIsClear? %d \nleftIsClear? %d", frontIsClear() ,rightIsClear(), leftIsClear() );
printf("\n\n");
int x,y;
for(x=0; x<height; x++){
for(y=0; y<width; y++){
if(karel.y==y && karel.x==x)
{
if (karel.direction == S) printf("v");
else if(karel.direction == E) printf(">");
else if(karel.direction == N) printf("^");
else if(karel.direction == W) printf("<");
}
else
{
if (world[x][y] == WALL) printf("#");
if (world[x][y] == EMPTY) printf(".");
if (world[x][y] > 0) printf("%d", world[x][y]);
}
}
printf("\n");
}
sleep(1000);
}
}
9 9 0 0 W 200
karelInWorld()
{
int x = karel_x;
int y = karel_y;
if (x <= width && y <= height && x>=0 && y >= 0) return 1; // width=6 height=5
else return 0;
}
frontIsClear()
{
int x = karel_x;
int y = karel_y;
if(karel_direction==0) x++; // v
else if(karel_direction==180)x--; // ^
else if(karel_direction==90) y++; // >
else if(karel_direction==270) y--; // <
if (karelInWorld() == 1);
{
if (world[x][y] == EMPTY && world[x][y] >= 0 ) return 1;
else return 0;
}
}
if (world[x][y] == EMPTY && world[x][y] >= 0 ) return 1;
else return 0;
#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0
int width,height;
int world[MAX_HEIGHT][MAX_WIDTH];
int karel_x;
int karel_y;
int karel_direction;
int karel_beepers = 20;
void turnOn(){
karel_y = 3;
karel_x = 3;
width=6;
height=5;
int newWorld[5][6]={
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, -1, -1, 0 }
};
karel_direction = 90;
int x,y;
for(x=0; x<height; x++){
for(y=0; y<width; y++)
world[x][y]=newWorld[x][y];
}
}
void draw()
{
system("cls");
printf("pozicia: %d %d \n",karel_x, karel_y);
printf("orientacia: ");
if (karel_direction == 0) printf("juh\n");
if (karel_direction == 180) printf("sever\n");
if (karel_direction == 270) printf("zapad\n");
if (karel_direction == 90) printf("vychod\n");
printf("pocet beeprov v batohu: %d\n", karel_beepers);
printf("tu je %d beeprov", world[karel_x][karel_y]);
printf(" \norientacia %d \nclear? %d\nblocked? %d \n", karel_direction, frontIsClear(), frontIsBlocked());
printf("\n");
int x,y;
for(x=0; x<height; x++){
for(y=0; y<width; y++){
if(karel_y==y && karel_x==x)
{
if (karel_direction==0) printf("v");
else if(karel_direction==90) printf(">");
else if(karel_direction==180) printf("^");
else if(karel_direction==270) printf("<");
}
else
{
if (world[x][y] == WALL) printf("#");
if (world[x][y] == EMPTY) printf(".");
if (world[x][y] > 0) printf("*");
}
}
printf("\n");
}
sleep(1000);
}
void turnLeft()
{
karel_direction += 90;
karel_direction = karel_direction % 360;
draw();
}
karelInWorld()
{
int x = karel_x;
int y = karel_y;
if (x <= width && y <= height && x>=0 && y >= 0) return 1; // width=6 height=5
else return 0;
}
frontIsClear()
{
int x = karel_x;
int y = karel_y;
if(karel_direction==0) x++; // v
else if(karel_direction==180)x--; // ^
else if(karel_direction==90) y++; // >
else if(karel_direction==270) y--; // <
if (karelInWorld() == 1);
{
if (world[x][y] == EMPTY && world[x][y] >= 0 ) return 1;
else return 0;
}
}
frontIsBlocked()
{
return !frontIsClear();
}
void movek()
{
int x,y;
if (frontIsClear() == 1)
{
if(karel_direction==0) karel_x++; //v
if(karel_direction==180) karel_x--; //^
if(karel_direction==90) karel_y++; //>
if(karel_direction==270) karel_y--; //<
draw();
}
else printf("\nchyba, je tu stena\n\n");
}
beepersInBag()
{
if (karel_beepers >= 1) return 1;
else return 0;
}
noBeepersInBag()
{
return !beepersInBag();
}
beepersPresent()
{
if (world[karel_y][karel_x] > 0) return 1;
else return 0;
}
putBeeper()
{
if (world[karel_y][karel_x] >= 0)
{
world [karel_y][karel_x] += 1;
karel_beepers--;
}
else printf("nie su tu beepre\n");
draw();
}
pickBeeper()
{
if (world[karel_y][karel_x] >0)
{
world [karel_y][karel_x] -= 1;
karel_beepers++;
}
else printf("tu nie ju beper");
draw();
}
void testSensors()
{
// printf("suradnice: x:%d y:%d \norientacia %d \nclear? %c\nblocked? %c \n", karel_x, karel_y, karel_direction, frontIsClear(), frontIsBlocked());
printf("\nma beepre? %d\npocet beeprov v batohu: %d \nje tu beeper? %d\n", beepersInBag(), karel_beepers, beepersPresent());
printf("tu je %d beeprov\n", world[karel_y][karel_x]);
}
Quote from: Jurosh on 24.04.2010, 05:29:55to si kde našiel?
...vie dokonca rozsirenu maticu 4x3...
Quote from: Jurosh on 24.04.2010, 05:32:53trojfázové budú len na skúške. A tuším tam budú aj tie grafy. Na zápočte bude len jednosmerný a harmonický. (alebo tak nejak sa to volá)
ja len dufam ze nebudu trojfazove neharmonicke stvorfazove a indukcna vezba na pisomke :-D bo to neni dobre.... nevykryvam tie veci do pondelka.... a ozdaj budu len nejake jednoduche tie ovody :O nvm jak vam ale mne sa ta elektro zda nejako brutalne tazka... matika1 je oproti tomu lahoda
Quote from: mimexko on 24.04.2010, 15:33:46mohol by si sem ten papier hodiť?
nam davala taky papier ze co bude a je tam ze v prvej ulohe napisat podmienkove rovnice pre JSO a este k tej otazke je aj vypocitat niektoru el. velicinu, takze matice budu velmi potrebne si myslim. chvalabohu nieje napisane akou metodou to riesit takze dufam ze ani v pisomke to nebude zadane. lebo metoda uzlovych napati je podla mna zbytocne velmi zlozita. horsie je ze moja kalkulacka nezvlada komlexne cisla. vie niekto sposob ako to vypocitat inym sposobom? jednoduchym
Quote from: puq on 23.04.2010, 00:03:45ako sa volal tipek, čo vynašiel PC myš, kedy bola dostavaná eiffelovka, a čerešnička na záver: akej rasy bol pes ktorý hral v komisárovi rexovi.
este pre zaujimavost ake boli otazky napriklad?
Quote from: stricky on 23.04.2010, 00:24:31ťažšie otázky jednoznačne...
ak mate nejake navrhy pre zlepsenie dalsieho kola tak ich postnite..
frontIsClear()
{
int x = karel_x;
int y = karel_y;
if(karel_direction==0) x++; // v
else if(karel_direction==180) x--; // ^
else if(karel_direction==90) y++; // >
else if(karel_direction==270) y--; // <
if (world[x][y] == EMPTY || x <= height || y <= width || x > 0 || y > 0 ) return 1;
else return 0;
}
frontIsBlocked()
{
return !frontIsClear();
Quote from: mirek on 20.04.2010, 02:02:24neviem, čo tam mám zle
skus sa este pozriet na to, ako pracujes s y-ovou a x-ovou osou v poli - ako ich pouzivas pri nacitavani pola v turnOn() a ako ich pouzivas v senzore frontIsClear()
Quote from: petopetolkoo on 20.04.2010, 02:06:53nemáš to jedno, či tam dám swich alebo if?
shwollo ten senzor urob radsej cez switch a nezabudaj kontrolovat aj hranice sveta, to jest height a width, kusok sa nad tym zamysli, nakresli si aj to pole ak ty to pomoze a skusaj hlavne skusaj
Quote from: Shwollo on 20.04.2010, 01:58:41dal som tam "1" a "0" a robí to presne to isté
wtf: return 'a' return 'n'![]()
#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0
int width,height;
int world[MAX_HEIGHT][MAX_WIDTH];
int karel_x;
int karel_y;
int karel_direction;
int karel_beepers = 20;
void turnOn(){
int i,j;
karel_x = 4;
karel_y = 3;
width=6;
height=5;
int newWorld[5][6]={
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, -1, -1, 0 }
};
karel_direction = 90;
for(i=0;i<height;i++){
for(j=0;j<width;j++)
world[i][j]=newWorld[i][j];
}
}
void draw()
{
system("cls");
printf("pozicia: %d %d \n",karel_x, karel_y);
printf("orientacia: karel je gay: ");
if (karel_direction == 0) printf("juh\n");
if (karel_direction == 180) printf("sever\n");
if (karel_direction == 270) printf("zapad\n");
if (karel_direction == 90) printf("vychod\n");
printf("pocet beeprov v batohu: %d\n", karel_beepers);
printf("tu je %d beeprov", world[karel_y][karel_x]);
printf(" \norientacia %d \nclear? %d\nblocked? %d \n", karel_direction, frontIsClear(), frontIsBlocked());
printf("\n");
int i,j;
for(i=0;i<height;i++){
for(j=0;j<width;j++){
if(karel_y==i && karel_x==j)
{
if (karel_direction==0) printf("v");
else if(karel_direction==90) printf(">");
else if(karel_direction==180) printf("^");
else if(karel_direction==270) printf("<");
}
else
{
if (world[i][j] == WALL) printf("#");
if (world[i][j] == EMPTY) printf(".");
if (world[i][j] > 0) printf("*");
}
}
printf("\n");
}
sleep(1000);
}
void turnLeft()
{
karel_direction += 90;
karel_direction = karel_direction % 360;
draw();
}
frontIsBlocked()
{
int x = karel_x;
int y = karel_y;
if(karel_direction==0) x++ ; //v <-y->
if(karel_direction==180) x--; //^ x
if(karel_direction==90) y++; //> |
if(karel_direction==270) y--; //< v
if (world[x][y] != EMPTY) return 1;
else return 0;
}
frontIsClear()
{
int x = karel_x;
int y = karel_y;
if(karel_direction==0) x++; // v
else if(karel_direction==180) x--; // ^
else if(karel_direction==90) y++; // >
else if(karel_direction==270) y--; // <
if (world[x][y] != WALL) return 1;
else return 0;
}
void movek()
{
int x,y;
if (frontIsClear() == 'a')
{
if(karel_direction==0) karel_x++; //v <-y->
if(karel_direction==180) karel_x--; //^ x
if(karel_direction==90) karel_y++; //> |
if(karel_direction==270) karel_y--; //< v
draw();
}
else printf("\nchyba, je tu stena\n\n");
}
beepersInBag()
{
if (karel_beepers >= 1) return 1;
else return 0;
}
noBeepersInBag()
{
return !beepersInBag();
}
beepersPresent()
{
if (world[karel_y][karel_x] > 0) return 1;
else return 0;
}
putBeeper()
{
if (world[karel_y][karel_x] >= 0)
{
world [karel_y][karel_x] += 1;
karel_beepers--;
}
else printf("nie su tu beepre\n");
draw();
}
pickBeeper()
{
if (world[karel_y][karel_x] >0)
{
world [karel_y][karel_x] -= 1;
karel_beepers++;
}
else printf("tu nie ju beper");
draw();
}
void testSensors()
{
// printf("suradnice: x:%d y:%d \norientacia %d \nclear? %c\nblocked? %c \n", karel_x, karel_y, karel_direction, frontIsClear(), frontIsBlocked());
printf("\nma beepre? %c\npocet beeprov v batohu: %d \nje tu beeper? %c\n", beepersInBag(), karel_beepers, beepersPresent());
printf("tu je %d beeprov\n", world[karel_y][karel_x]);
}