Advertisement
verochubut

Clase 6 Ejercicio 3c

Sep 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.93 KB | None | 0 0
  1. //Denota el color utilizado para representar a los Animales//
  2.     function colorDeAnimales(){
  3.     return(Rojo)
  4. }
  5.  
  6. //Denota el color utilizado para representar a los Cultivos//
  7.     function colorDeCultivos() {
  8.     return(Verde)
  9. }
  10.  //Denota el color utilizado para representar a los Construcciones//
  11.     function colorDeConstrucciones() {
  12.     return(Negro)
  13. }
  14.  
  15. //Denota el color utilizado para representar a los Cultivos//
  16.     function colorDeAgua() {
  17.     return(Azul)
  18. }
  19.  
  20. /*Funciones para denotar las cantidades de cada
  21. elemento presentes en la hectarea actual*/
  22.  
  23. function cantidadDeAnimales() {
  24. return(nroBolitas(colorDeAnimales()))
  25. }
  26.  
  27. function cantidadDeConstrucciones() {
  28. return(nroBolitas(colorDeConstrucciones()))
  29. }
  30.  
  31. function cantidadDeCultivos() {
  32. return(nroBolitas(colorDeCultivos()))
  33. }
  34.  
  35. function cantidadDeAgua() {
  36. return(nroBolitas(colorDeAgua()))
  37. }
  38.  
  39. //Denota la cantidad mas animales que cultivos en la hectarea //
  40. function masAnimalesQueCultivos(){
  41. return (cantidadDeAnimales()> (cantidadDeCultivos()))
  42. }
  43.  
  44.  
  45. /*EJERCICIO 1A DE LA GRANJA*/
  46. function hayCultivos(){
  47. return (nroBolitas(Verde)>0)
  48. }
  49.  
  50.  
  51. function cultivoEnPeligro() {
  52. return (hayCultivos() && masAnimalesQueCultivos())
  53. }
  54.  
  55.  
  56. /*EJERCICIO 1B DE LA GRANJA*///Contrucciones en Peligro//
  57.  
  58. function hayConstrucciones(){
  59. return (nroBolitas(Negro)>0)
  60. }
  61.  
  62. function tripleDeAnimalesEnConstruccion(){
  63. return (cantidadDeAnimales()>=cantidadDeConstrucciones()*3)
  64. }
  65.  
  66. function construccionesEnPeligro(){
  67. return (hayConstrucciones()&& tripleDeAnimalesEnConstruccion())
  68. }
  69.  
  70. /*EJERCICIO 1C DE LA GRANJA*///*HECTAREA EN PELIGRO*/
  71.  
  72. function hectareaEnPeligro(){
  73. return (construccionesEnPeligro()|| cultivoEnPeligro())
  74. }
  75. /*EJERCICIO 1D DE LA GRANJA*///*HECTAREA EN PELIGRO AL DIR*/
  76.  
  77. procedure PuedeMoverDir(dir){
  78.     if (puedeMover(dir))
  79.     {Mover(dir)}
  80. }
  81.  
  82. function hectareaEnPeligroAl(dir){
  83.     //Mover(dir)
  84.     PuedeMoverDir(dir)
  85.     return(hectareaEnPeligro())
  86. }
  87.  
  88. /*Ejercicio 2 ANIMALES EXCEDENTES*/
  89.  
  90.  
  91. function excedenteAnimalesEnCultivos(){
  92. return (cantidadDeAnimales()-cantidadDeCultivos())
  93. }
  94.  
  95. function excedenteAnimalesEnConstrucciones(){
  96. return( cantidadDeAnimales()-cantidadDeConstrucciones()*3)
  97. }
  98.  
  99.  
  100. function animalesExcedentes(){
  101. if (excedenteAnimalesEnCultivos() > excedenteAnimalesEnConstrucciones()){
  102. excedente :=(excedenteAnimalesEnCultivos())}
  103. else
  104. {
  105. excedente := (excedenteAnimalesEnConstrucciones())
  106. }
  107.  
  108. return(excedente)
  109. }
  110.  
  111. /*Ejercicio 3A RESOLVER COMPLICTO EN HECTAREA*/
  112.  
  113. procedure MoverAnimalesExcedentesAl(dir){
  114. excedente := animalesExcedentes()
  115. repeatWith a in 1..excedente
  116. {Sacar(Rojo)}
  117. PuedeMoverDir(dir)
  118. repeatWith i in 1..excedente
  119. {Poner(Rojo)}
  120. }
  121.  
  122. procedure ResolverConflictoEnHectarea(){
  123. if(puedeMover(Este) && hectareaEnPeligroAl(Este)){
  124. MoverAnimalesExcedentesAl(Norte)}
  125. else
  126. {if(puedeMover(Este) == False)
  127. {MoverAnimalesExcedentesAl(Norte)}
  128.  
  129. if (hectareaEnPeligroAl(Este) == False)
  130. {MoverAnimalesExcedentesAl(Este)}
  131. }
  132.  
  133. }
  134.  
  135.  
  136. /*Ejercicio 3B RESOLVER COMPLICTO EN HECTAREA*/
  137.  
  138. procedure ProcesarHectarea(){
  139. if (hectareaEnPeligro()){
  140. ResolverConflictoEnHectarea()}
  141. }
  142.  
  143.  
  144. /*Ejercicio 3C PROCESAR CAMPO SIN BORDE*/
  145. //*para resolver este ejercicio utilice partes del ejercicio entregable 5 y mirando consejos encontrados en el foro y salio*//
  146.  
  147.  
  148. function adaptarHectarea(){
  149.     return(puedeMover(Este)|| puedeMover(Norte))
  150. }
  151.  
  152. procedure IrAlBorde(dir){
  153.     while(puedeMover(dir))
  154.     {Mover(dir)}
  155. }
  156.  
  157. procedure VolverAlOrigenYSubir() {
  158.     IrAlBorde(Oeste)
  159.     Mover(Norte)
  160. }
  161.  
  162. procedure IrASiguienteHectarea() {
  163.     if(puedeMover(Este))
  164.     {Mover(Este)}
  165.     else
  166.     {VolverAlOrigenYSubir()}
  167. }
  168.  
  169. function estaEnBorde (){
  170.     return (not puedeMover (Norte ))
  171. }
  172.  
  173.  
  174. procedure ProcesarCampoSinBorde (){
  175.         while (not estaEnBorde ()){
  176.         ProcesarHectarea()
  177.         IrASiguienteHectarea()
  178.     }
  179. }
  180.  
  181.  procedure Main (){
  182.     ProcesarCampoSinBorde()
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement