Close
Duke shfaqur rezultatin -9 deri 0 prej 6
  1. #1
    i/e regjistruar Maska e javac
    Anëtarësuar
    30-10-2005
    Vendndodhja
    GJILAN
    Postime
    35

    Duhet të bëj lojën "Life"!

    Pershendetje.
    E kom detyre me bo lojen "Life" qe edhe ma posht n'kod tregon teksti i komentuar ma saktsisht, po kom ngec n'fillim e kom ni gabim semantik. E kom algoritmin qe me kontrollu matricen kshtu qe s'pari e kontrolloj per termat e brendshem d.m.th. i>0, j>0, i
    Kodi:
    /* Write an animation that lets the computer play the game of ``Life.'' 
    The game goes as follows: the user specifies the size of game board, 
    a matrix, and also gives the starting positions of where some pebbles(``cells'') live. 
    Every second, the computer updates the board, creating and removing cells, 
    according to the following rules: 
        - an empty board position that is surrounded by exactly three cells gets
          a cell placed on it. (The new cell ``comes to life.'') 
        - a board position occupied by a cell retains the cell if the position was surrounded
          by exactly 2 other cells. (Otherwise the cell disappears---``dies''---due to 
         ``loneliness'' or ``overcrowding.'') 
    Here is an example of two seconds of the animation on a 5-by-5 board, where an X denotes a cell and . denotes an empty space: 
    .X.XX     ...XX     ...XX
    X...X     ....X     ....X
    XXX..  => X.X..  => ...X.
    ..X.X     X.X..     ..XX.
    X...X     ...X.     .....
    */
    import java.awt.*;
    import javax.swing.*;
    public class LifeFinal
    {    char[][] c = new char[5][5];
        char[][] m = new char[5][5];
        public LifeFinal()
        {  c[0][0] = '.'; c[0][1] = 'x'; c[0][2] = '.'; c[0][3] = 'x'; c[0][4] = 'x';   
            c[1][0] = 'x'; c[1][1] = '.'; c[1][2] = '.'; c[1][3] = '.'; c[1][4] = 'x';
            c[2][0] = '.'; c[2][1] = '.'; c[2][2] = 'x'; c[2][3] = '.'; c[2][4] = '.'; 
            c[3][0] = '.'; c[3][1] = '.'; c[3][2] = 'x'; c[3][3] = '.'; c[3][4] = 'x'; 
            c[4][0] = 'x'; c[4][1] = '.'; c[4][2] = '.'; c[4][3] = '.'; c[4][4] = '.';
         }
        
        public void save()
        {    m = c; }
        public void print()
        {    for(int i = 0; i < m.length; i++)
            {    for(int j = 0; j < m[0].length; j++)
                {    System.out.print(m[i][j] + " ");
                }
                System.out.println();
            }
            System.out.println();
        }
        public void check_it()
        {    c = m;
            int three = 0; 
            int two = 0;
            for(int i = 0; i < c.length; i++)
            {    for(int j = 0; j < c[0].length; j++)
                {    three = 0;
                    two = 0;
                    if(i>0 && j>0 && i
    

  2. #2
    i/e regjistruar Maska e javac
    Anëtarësuar
    30-10-2005
    Vendndodhja
    GJILAN
    Postime
    35
    a po e e gjeta...
    kopjimi i matricave s'lejohet kshtu thjeshte c = a duhet me kopju c'do term nje nga nje. Megjithate thnx:P

  3. #3
    i/e regjistruar
    Anëtarësuar
    18-09-2004
    Vendndodhja
    DE
    Postime
    15
    Citim Postuar më parë nga javac Lexo Postimin
    a po e e gjeta...
    kopjimi i matricave s'lejohet kshtu thjeshte c = a duhet me kopju c'do term nje nga nje. Megjithate thnx:P
    Kopjimi i matrices lejohet c=a nuk eshte e nevojshme te kopjosh secilin element te matrices psh.

    Kodi:
    public class ProveMatrix {
    	public static void main(String[] arg){
    		int[][] a={{1,2,3,4},
    				{2,3,4,3}};
    		int[][] b=a;
    		}
    
    }
    Mire qe e ke zgjedh problemin, po shpenzimi i kohes(time costs) per kete program eshte shume i madh, paramendo te kesh nje matric me te madhe se 5x5. A nuk egziston ndonje alogortem me i mire per kete problem, edhe pse nuk po e di se si funksionon kjo loje..

    Shendet
    Live fast, die young

  4. #4
    Ne ca gjuhe eshte ky kodi?
    Keyboard not found .... press any key to continue!

  5. #5
    i/e regjistruar
    Anëtarësuar
    18-09-2004
    Vendndodhja
    DE
    Postime
    15
    Citim Postuar më parë nga Ditmir Zhuka Lexo Postimin
    Ne ca gjuhe eshte ky kodi?
    nqs "ca = cfare" atehere eshte gjuha programuese Java

    Me te mira
    Live fast, die young

  6. #6
    i/e regjistruar Maska e javac
    Anëtarësuar
    30-10-2005
    Vendndodhja
    GJILAN
    Postime
    35
    Citim Postuar më parë nga MaLoKu Lexo Postimin
    Kopjimi i matrices lejohet c=a nuk eshte e nevojshme te kopjosh secilin element te matrices psh.

    Kodi:
    public class ProveMatrix {
    	public static void main(String[] arg){
    		int[][] a={{1,2,3,4},
    				{2,3,4,3}};
    		int[][] b=a;
    		}
    
    }
    Mire qe e ke zgjedh problemin, po shpenzimi i kohes(time costs) per kete program eshte shume i madh, paramendo te kesh nje matric me te madhe se 5x5. A nuk egziston ndonje alogortem me i mire per kete problem, edhe pse nuk po e di se si funksionon kjo loje..

    Shendet
    heeem...ashtu qysh e ke bo ti, b permban adresen e a-s dhe i referohet a-s, nuk eshte nje variabel n'vete qe i permban qato elemente! Te detyra jem ndodhi ky problem. N'at menyre une isha kon tu punu me matricen e njejte pa i rujt ndryshimet askund. E kete kopjimin e matricave p.sh. b = a nuk a kan lon n'Java per mos me zene vend shume pa nevoje n'memorie se matricat jon t'mdhaja, pra ne ket rast b = a, b permban adresen e a-se. E kopjimi nuk osht problem me ciklet for, i < b.length blabla...sado e madhe qe t'jete matrica.
    Mund edhe t'jem gabim po kaq po m'kujtohen senet prej fakultetit edhe sha i kom provu

    Ja dhe loja kush osht kurreshtar
    Skedarët e Bashkëngjitur Skedarët e Bashkëngjitur
    Ndryshuar për herë të fundit nga javac : 26-06-2008 më 03:33

Regullat e Postimit

  • Ju nuk mund të hapni tema të reja.
  • Ju nuk mund të postoni në tema.
  • Ju nuk mund të bashkëngjitni skedarë.
  • Ju nuk mund të ndryshoni postimet tuaja.
  •