Link to home
Start Free TrialLog in
Avatar of wolfinator
wolfinator

asked on

Palm program

I am having a lot of trouble with Palm and C..
I have to develop a palm program that is a Sudoku game. The game is only a 4-by-4 cell and it follows all of the rules of Sudoku. I can post my header file now, if needed in order for someone to help me. I also have some of the code on checking the fields, but as of now I am very stuck. The board is in the form of text fields also(fyi).. Thank you for any help.
Avatar of wolfinator
wolfinator

ASKER

I wrote this function to check rows and columns for double occurances of a number.. but i am not sure how to implement it using the text fields in palm..

int board[4][4];
int prevBoard[4][4];
int rowMask[4];
int colMask[4];
int MiniMatrix[4];


boolean function checking(x1, x2, x3, x4)
{
      boolean result[5];
        for(i=1, i<=4, i++)
        {
            result[i] = false;
        }
        if(result[x1] && x1 != 0)
        {
            return false;
        }
        else
        {
            return[x1] = true;
        }


        if(result[x2] && x2 != 0)
        {
            return false;
        }
        else
        {
            return[x2] = true;
        }

        if(result[x3] && x3 != 0)
        {
            return false;
        }
        else
        {
            return[x3] = true;
        }

        if(result[x4] && x4 != 0)
        {
            return false;
        }
        else
        {
            return[x4] = true;
        }

}

FYI: this is due by tuesday 12am, I will continue to work on this as hard as possible, but I am truly jammed.

Thank you
pointer to previous Q: http:Q_21737640.html

> I am having a lot of trouble with Palm and C..

Could you tell us what you currently have running?
Do you have a kind of "hello world" application running on your palm?
Are you able to draw the board?
Are you able to process user input?

You need to split your assignment into small pieces. You can't create the whole program in a single step. It would be easier to first concentrate on the user interface, because you can see if it is working or not.
btw, in your previous post you posted a link to a powerpoint drawing. Do you also have it in another format, as I don't have powerpoint installed?
What do you mean currently have running??
I did have a hello world app at one time, if i need it to edit this; i can get it.
I have the rcp totally written if you would like to see it.


Here is a zip file that breaks the flowchart I posted into .bmps
http://www.cs.pitt.edu/~khalifa/cs449/spr06/recitations/mw/Proj2_Flowchart_bmpFiles.zip
> What do you mean currently have running??

I don't exactly understand where you are stuck, and I don't know how much guidance you need.

Looking at the flowchart, you need at least the following functions:
     Eventhandler / Main loop
     ResetBoard
     SubmitMove
     UndoMove
     GenerateSolution
     ShowHint

I would suggest the order as shown above. Break difficult functions into smaller steps. Each part is relative easy, and you will see your program getting larger each time something is finished.
ok..see i am having loads of trouble.. I am so new to both of these parts of CS, I don't even know how to connect buttons with functions and such..

I was hoping you or someone could help me get on the right track. I am using Palm OS Developer Suite to make this thing. I'll post my header file so you can get an idea of what my form looks like..

I feel like i should start somewhere along the lines of making a user input function. Do you agree?



.h file:

FORM ID 1000 AT (0 0 160 160)
      NOFRAME NOSAVEBEHIND USABLE
      
BEGIN
      TITLE "Sudoku Puzzle"
      BUTTON "Submit" ID 1016 AT (9 120 36 16) USABLE RIGHTANCHOR FRAME
      BUTTON "Undo" ID 1017 AT (48 120 36 16) USABLE RIGHTANCHOR FRAME
      BUTTON "Reset" ID 1018 AT (88 120 36 35) USABLE LEFTANCHOR FRAME
      BUTTON "GenSol" ID 1019 AT (9 139 36 15) USABLE RIGHTANCHOR FRAME
      BUTTON "Hint" ID 1020 AT (48 139 36 15) USABLE RIGHTANCHOR FRAME
      FIELD ID 1021 AT (90 44 14 16) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1022 AT (126 45 14 16) USABLE LEFTALIGN EDITABLE MULTIPLELINES MAXCHARS 80
      LABEL "PC" ID 1023 AT (92 28) USABLE
      LABEL "Score" ID 1024 AT (124 29) USABLE
      FIELD ID 1025 AT (91 92 63 13) USABLE LEFTALIGN NONEDITABLE SOLIDUNDERLINED MULTIPLELINES DYNAMICSIZE MAXCHARS 80
      LABEL "Status:" ID 1026 AT (91 73) USABLE
      LABEL "0" ID 1027 AT (94 44) USABLE FONT 7
      LABEL "0" ID 1028 AT (130 45) USABLE FONT 7
      FIELD ID 1000 AT (7 20 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1001 AT (25 20 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1002 AT (7 20 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1003 AT (44 20 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1004 AT (7 43 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1005 AT (25 43 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1006 AT (7 43 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1007 AT (44 43 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1008 AT (7 66 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1009 AT (25 66 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1010 AT (7 66 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1011 AT (44 66 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1012 AT (7 89 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1013 AT (25 89 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1014 AT (7 89 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1015 AT (44 89 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1029 AT (62 20 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1030 AT (62 43 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1031 AT (62 66 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      FIELD ID 1032 AT (62 89 18 22) NONUSABLE LEFTALIGN EDITABLE MULTIPLELINES NUMERIC HASSCROLLBAR MAXCHARS 80
      LABEL "2" ID 1033 AT (13 22) USABLE FONT 6
      LABEL "1" ID 1034 AT (12 44) USABLE FONT 6
      LABEL "4" ID 1035 AT (49 45) USABLE FONT 6
      LABEL "3" ID 1036 AT (66 91) USABLE FONT 6
      LABEL "12 cells left " ID 1037 AT (93 91) USABLE FONT 1
END
> I feel like i should start somewhere along the lines of making a user input function. Do you agree?

Yes, I think that is fine, and if an input is selected, just show an alert, such as "you have pressed Reset".

I do have a palm myself, but I never have written a program for it. So I can't help you much with palm specific things.
I wrote this code to get the value from the text field.. can you tell me if it right? or if i should change anything?


static void getCellValue(int row, int col){

   char buffer[4];
   FormType *form = FrmGetActive();
   FieldType *field;
   int fieldID = getCellID(row,col);
   int value;

   field = FrmGetObjectPtr(form, FrmGetObjectIndex(form, fieldID));

      if(FldGetTextLength(field) > 0)
      {
         strcpy(buffer, FldGetTextPtr(field));
         value = atoi(buffer);
         if(value == 0)
            return -1;
         else
            return value;
      }
      else
      {
         return 0;
      }
}
Looks ok, although this line:
     strcpy(buffer, FldGetTextPtr(field));
might be dangerous if FldGetTextPtr returns a pointer to a string longer than 3 characters. Maybe it is better to use:
     value = atoi(FldGetTextPtr(field));

When searching for the meaning of FldGetTextPtr, I saw there is a TA for palm programming questions. It is not very active, but you can at least try to put a pointer (https://www.experts-exchange.com/help.jsp#hi262) to this question.
https://www.experts-exchange.com/Programming/Wireless_Programming/Palm_Pilot/
ok..well..it is very inactive and i am running very very low on time..I was wondering if you could help me implement the last code i sent you to work together with some other code to check if it violates the number being used two times in a row or column.. It checks this after i hit the submit button. Therefore:

  switch (event->data.ctlSelect.controlID)
               {
                      case SubmitButton:
                            if(

//then the code to check if it violates anything.
//Or in this case do you think the first portion of code 'boolean checking' would work with this somehow??
Just so you know what my actual goal here is..This is the .prc file for what I am supposed to be making..

http://www.cs.pitt.edu/~khalifa/cs449/spr06/Assignments/Assign3/sudokuXins.prc

ASKER CERTIFIED SOLUTION
Avatar of cwwkie
cwwkie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
now..it would seem to me you would do the reverse of the first function to check the columns, right??

Do you have any idea how i could display an error i created when there is an invalid board??

like if(Testboard returns false) then display error..but any idea how i could implement that??
> now..it would seem to me you would do the reverse of the first function to check the columns, right??
Yes, I think you can do that yourself. The 2x2 fields are a bit more difficult, but you can solve that without a loop.

> Do you have any idea how i could display an error i created when there is an invalid board??
> like if(Testboard returns false) then display error..but any idea how i could implement that??
No, I think you need to search an example program.

Maybe something like http://www.tabdee.ltd.uk/Software/Papers/PalmOSProgramming/PalmOSProgramming.html

ALERT AlertIncompatible ERROR
BEGIN
    TITLE 'Incompatible OS'
    MESSAGE 'System version ^1 or higher is required'
    BUTTONS  'OK'
END;