לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 22-03-2011, 15:17
  benni7 benni7 אינו מחובר  
 
חבר מתאריך: 08.11.07
הודעות: 34
שאלה בגאוה

השאלה שלי היא כללית יותר אבל אם יהיה לא מובן אני אביא כבר הכל בדיוק אותו דבר

יש פונקציה שרוצים שאני אכתוב לחשב מספר שינויים של מהלך במשחק רוורסי


public static int benefit(int[][] board, int player, int row, ont column)
המונה ומחזירה את תועלת המהלך, כלומר את מספר הדסקיות היריב שהשתנו בעקבות המהלך.

הבעיה היא שהשינויים שנעשים בכל מהלך נעשים בפונקציה אחרת כך ששם הרבה יותר קל פשוט למנות אותם אחרי כל שינוי....

איך אני יכול לעשות את זה דרך פונקציה חיצונית...(benefit) אני גם צריך שהיא תחזיר את סך כל השינויים ולא רק לזמן אותה בכניסה לכל לולאה...
כלומר היא צריכה לפעול אחרי כל השינויים שנעשים ולא כל פעם שנעשה שינוי בודד.



מישהו הבין בכלל מה אני רוצה ?

הנה הפונקציה השניה שמבצעת את השינויים אולי זה יסביר יותר טוב למה אני לא מבין איך למנות את סך כל השינויים באמצעות BENEFIT :


public static int[][] play(int[][] board, int player, int row, int column){

if (isLegal(board,player,row,column)){
if (isLegalrowright(board,player,row,column)){
//switching row right according to rules
int j=column;
while (j<=board[row].length-1&&board[row][j]!=player){
board[row][j]=player;
j=j+1;
}//while

}
if (isLegalrowleft(board,player,row,column)){
//switching row left according to rules
int j=column;
while (board[row][j]!=player&&j>=0){
board[row][j]=player;
j=j-1;
}//while
}
if (isLegalcoldown(board,player,row,column)){
//switching column down according to rules
int i=row;
while (board[i][column]!=player&&i<=board.length-1){
board[i][column]=player;
i=i+1;
}//while
}
if (isLegalcolup(board,player,row,column)){
//switching column up according to rules
int i=row;
while (board[i][column]!=player&&i>=0){
board[i][column]=player;
i=i-1;
}//while
}
if (isLegaldiadownleft(board,player,row,column)){
//switching diagonal down left according to rules

int i=row;
int j=column;
while (board[i][j]!=player&&i<=board.length-1&&j>=0){
board[i][j]=player;
i=i+1;
j=j-1;
}//while


}
}
if (isLegaldiaupright(board,player,row,column)){
//switching diagonal up right according to rules
int i=row;
int j=column;
while (board[i][j]!=player&&i>=0&&j<=board[i].length-1){
board[i][j]=player;
i=i-1;
j=j+1;
}//while
}
if (isLegaldiadownright(board,player,row,column)){
//switching diagonal down right according to rules
int i=row;
int j=column;
while (board[i][j]!=player&&i<=board.length-1&&j<=board[i].length-1){
board[i][j]=player;
i=i+1;
j=j+1;
}//while
}
if (isLegaldiaupleft(board,player,row,column)){
//switching diagonal up left according to rules
int i=row;
int j=column;
while (board[i][j]!=player&&i>=0&&j<=0){
board[i][j]=player;
i=i-1;
j=j-1;
}//while
}


תודה מראש.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #3  
ישן 22-03-2011, 19:54
  benni7 benni7 אינו מחובר  
 
חבר מתאריך: 08.11.07
הודעות: 34
בתגובה להודעה מספר 2 שנכתבה על ידי benni7 שמתחילה ב "[B]בעע זה נראה ממש מסורבל הנה..."

הנה ערכתי באנגלית זה הרבה יותר ברור עכשיו :


Help on some work i got ! Reversi game
hey guys

i have a question i got for homework

the program is a basicly an Othelo/Reversi game

ive been writing some functions that changes the board according to legal playes
and now im being asked to create a function(BENEFIT) that counts the amount of enemy discs changeed based on the last play.


public static int benefit(int[][] board, int player, int row, int column){

int ans = 0;// YOU CAN CHANGE IT !!



return ans;
}//end of benefit

problem is its easied to count the maount of changes in the "play" function using COUNT++;

but i have no idea how am i suppose to use Benefit Function in order to count those changes. moreover it should sum the total amount of changes not only change per row/col/diagonal , instead it needs to return the changes of row+col+diagonal of a single play.


can anyone help me out?


heres some of the play function if it helps (the way ive written it anyways):
public static int[][] play(int[][] board, int player, int row, int column){
if (isLegal(board,player,row,column)){
if (isLegalrowright(board,player,row,column)){
//switching row right according to rules
int j=column;
while (j<=board[row].length-1&&board[row][j]!=player){
board[row][j]=player;
j=j+1;
}//while

}
if (isLegalrowleft(board,player,row,column)){
//switching row left according to rules
int j=column;
while (board[row][j]!=player&&j>=0){
board[row][j]=player;
j=j-1;
}//while
}
exc...
u can see adding co++ after board[row][j]=player will be the easiest solution but its not what i asked .. sadly.


thanks for help and sorry for length.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #4  
ישן 23-03-2011, 18:36
צלמית המשתמש של Eran
  משתמש זכר Eran Eran אינו מחובר  
 
חבר מתאריך: 27.02.02
הודעות: 4,536
שלח הודעה דרך ICQ אל Eran
בתגובה להודעה מספר 1 שנכתבה על ידי benni7 שמתחילה ב "שאלה בגאוה"

ציטוט:
במקור נכתב על ידי benni7
קוד:
public static int[][] play(int[][] board, int player, int row, int column){



השיטה לא תקינה איפה הפלט??? (אין בזה return!)


ולגבי השאלה שלך, לפי הכותרות של השיטות כל שעליך לעשות זה להעתיק ממש את השיטה play
להוסיף int של מונה ולמנות כמובן את השינויים (אמרת שב play אתה יודע לעשות את זה), בסוף השיטה להחזיר את המונה במקום את הלוח.
_____________________________________

[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://fresh.clanteam.com/list.png]

[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://fresh.clanteam.com/?https://2010-uploaded.fresh.co.il/2010/09/21/52868411.gif,http://www.boredpanda.com/blog/wp-content/themes/mimbo2.2/images/subscribe-panda-605px.png]

תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 18:31

הדף נוצר ב 0.05 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר