Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,301 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,007 people online right now. Registration is fast and FREE... Join Now!




need help about life's game

 
Reply to this topicStart new topic

need help about life's game, In console mode only

ZeroX18
post 22 Sep, 2008 - 07:29 PM
Post #1


New D.I.C Head

*
Joined: 22 Sep, 2008
Posts: 3

hi! I am a basic c# programmer , but last week my teacher let us work in console mode for the Game of Life and I found only it in visual mode. I would appreciate if someone could give me the code for console mode.
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 22 Sep, 2008 - 07:38 PM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,923



Thanked 118 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM

Go to the top of the page

ZeroX18
post 22 Sep, 2008 - 08:12 PM
Post #3


New D.I.C Head

*
Joined: 22 Sep, 2008
Posts: 3

this is the problem... I had no idea how to start this exercise.. as far I know, It need an array, but I dont know how to call this function... if I only know how to start, I can do it.

This post has been edited by ZeroX18: 22 Sep, 2008 - 08:17 PM
User is offlineProfile CardPM

Go to the top of the page

ZeroX18
post 1 Oct, 2008 - 03:52 PM
Post #4


New D.I.C Head

*
Joined: 22 Sep, 2008
Posts: 3

ok... after 5 days I solved the problem, but I have another problem now...

CODE
        protected int ObtenVec(int x, int y)
        {
            
            return
                (x > 0 && y > 0 ? (estadoac[x - 1 + (y - 1) * this.cols] ? 1 : 0) : 0) +
                (y > 0 ? (estadoac[x + (y - 1) * this.cols] ? 1 : 0) : 0) +
                (x + 1 < cols && y > 0 ? (estadoac[x + 1 + (y - 1) * this.cols] ? 1 : 0) : 0) +
                (x + 1 < cols ? (estadoac[x + 1 + y * this.cols] ? 1 : 0) : 0) +
                (x + 1 < cols && y + 1 < filas ? (estadoac[x + 1 + (y + 1) * this.cols] ? 1 : 0) : 0) +
                (y + 1 < filas ? (estadoac[x + (y + 1) * this.cols] ? 1 : 0) : 0) +
                (x > 0 && y + 1 < filas ? (estadoac[x - 1 + (y + 1) * this.cols] ? 1 : 0) : 0) +
                (x > 0 ? (estadoac[x - 1 + y * this.cols] ? 1 : 0) : 0);
        
        }

This code... I need to find another way to represent that, I heard that I can modify it into if or switch... But I tried and can't did it, plz... need help..
User is offlineProfile CardPM

Go to the top of the page

Jayman
post 1 Oct, 2008 - 04:56 PM
Post #5


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,839



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


You could do it in a switch, or actually series of switch statements, and then return the total value by keeping a running total.

Here I have done the first two for you. I leave it up to you to modify the rest.

Don't forget about order of operations when using parenthesis.
CODE

            int total = 0;
            // The following statement will evaluate to the following switch statement
            // (x > 0 && y > 0 ? (estadoac[x - 1 + (y - 1) * this.cols] ? 1 : 0) : 0)
            switch (estadoac[x - 1 + (y - 1) * this.cols])
            {
                case true:
                    switch (x > 0 && y > 0)
                    {
                        case true:
                            //Add one to total
                            total++;
                            break;
                        case false:
                            //Result is 0, so do not need to add to total
                            break;
                    }
                    break;
                case false:
                    //Do not need to add anything to total as both results are 0
                    break;
            }

            // The following statement will evaluate to the following switch statement
            // (y > 0 ? (estadoac[x + (y - 1) * this.cols] ? 1 : 0) : 0)
            switch (estadoac[x + (y - 1) * this.cols])
            {
                case true:
                    switch (y > 0)
                    {
                        case true:
                            //Add one to total
                            total++;
                            break;
                        case false:
                            //Result is 0, so do not need to add to total
                            break;
                    }
                    break;
                case false:
                    //Do not need to add anything to total as both results are 0
                    break;
            }

        }
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:48AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month