fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. #define MY_LIFE 3
  6.  
  7. #define SOUL(MY) (0xFFFF & MY)
  8. #define BODY(MY) (MY>>0x10)
  9.  
  10. enum emotion {
  11. neutral,
  12. upbeat,
  13. sleepy, tired, pessimistic, betrayed, mad, afraid, down, left_behind
  14. };
  15.  
  16. const char bormand[] = "x!( \"@\"!, #(&!$ $\\&!$ %('!$ &T&! 'T& $ !, %0&!$ $X&!$ #$&!$ )$& $ ";
  17.  
  18. const int p_x = 15;
  19. const int p_y = 10;
  20.  
  21. unsigned int podushka[p_x * p_y];
  22.  
  23. unsigned int embrace(const char* a, int i) {
  24. unsigned int x = 0;
  25. for(int j = 0; j<3; ++j)
  26. x += (a[i+j]-0x20)<<(j*6);
  27. return x;
  28. }
  29.  
  30. void make_love(int x, int y) {
  31. unsigned int my = podushka[x + p_x*y];
  32. int my_soul = SOUL(my);
  33. if (my_soul >= sizeof(bormand) - 3)
  34. return;
  35. int my_happiness = embrace(bormand, my_soul);
  36. int dx = 0;
  37. int dy = 0;
  38. switch(my_happiness & 0xFF) {
  39. case upbeat:
  40. podushka[x + y*p_x] = my_soul + MY_LIFE + ((my_happiness & 0xFFFF00)<<8);
  41. break;
  42. case sleepy:
  43. dx = -1; goto sleep;
  44. case tired:
  45. dx = -1; dy = -1; goto sleep;
  46. case left_behind:
  47. dx = -1; dy = 1; goto sleep;
  48. case mad:
  49. dx = 1; goto sleep;
  50. case betrayed:
  51. dx = 1; dy = -1; goto sleep;
  52. case afraid:
  53. dx = 1; dy = 1; goto sleep;
  54. case pessimistic:
  55. dy = -1; goto sleep;
  56. case down:
  57. dy = 1; goto sleep;
  58. sleep:podushka[(x+dx)%p_x + (y+dy)%p_y*p_x] = BODY(my) ? my - 0x10000 : my_soul + MY_LIFE;
  59. podushka[x + p_x*y] = my_happiness>>8;
  60. break;
  61. default:
  62. return;
  63. }
  64. }
  65.  
  66. int main(int argc, const char * argv[]) {
  67. //cout<<"Bormand: \"" << bormand << "\"\n";
  68. podushka[8+p_x*9] = 1;
  69. // Test
  70. //print2();
  71. for (int t = 0; t<20; ++t) {
  72. for (int i = 0; i<p_x*p_y; ++i)
  73. make_love(i%p_x, i/p_x);
  74. //cout << "step: "<<t<<endl;
  75. //print2();
  76. }
  77. for (int j = 0; j<p_y; ++j) {
  78. for (int i = 0; i<p_x; ++i) {
  79. auto c = podushka[i+p_x*j];
  80. putchar((c>0x20 && c <0x7e)?(char)c:' ');
  81. }
  82. cout<<endl;
  83. }
  84. return 0;
  85. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
               
   mmm   aa    
  r   % aaaa   
 r     @@ aaa  
 o        nnn  
 o        nnn  
  b      ddd   
   b    ddd    
    b  ddd     
     bddd