forked from sureshdr/mhora
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Strengths.cs
1382 lines (1273 loc) · 41.4 KB
/
Strengths.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******
Copyright (C) 2005 Ajit Krishnan (http://www.mudgala.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******/
using System;
using System.Collections;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using System.ComponentModel;
using System.Globalization;
namespace mhora
{
public class EqualStrength: Exception
{
}
public interface IStrengthNakshatra
{
bool stronger (Nakshatra m, Nakshatra n);
}
public interface IStrengthGraha
{
bool stronger (Body.Name m, Body.Name n);
}
public interface IStrengthRasi
{
bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb);
}
abstract public class BaseStrength
{
protected ArrayList std_grahas;
protected Division dtype;
protected ArrayList std_div_pos;
protected Horoscope h;
protected bool bUseSimpleLords;
protected Body.Name GetStrengthLord (ZodiacHouse.Name zh)
{
if (bUseSimpleLords)
return Basics.SimpleLordOfZodiacHouse(zh);
else
return h.LordOfZodiacHouse(new ZodiacHouse(zh), dtype);
}
protected Body.Name GetStrengthLord (ZodiacHouse zh)
{
return GetStrengthLord (zh.value);
}
protected BaseStrength (Horoscope _h, Division _dtype, bool _bUseSimpleLords)
{
h = _h;
dtype = _dtype;
bUseSimpleLords = _bUseSimpleLords;
std_div_pos = h.CalculateDivisionPositions (dtype);
}
protected int numGrahasInZodiacHouse (ZodiacHouse.Name zh)
{
int num = 0;
foreach (DivisionPosition dp in std_div_pos)
{
if (dp.type != BodyType.Name.Graha)
continue;
if (dp.zodiac_house.value == zh)
num = num + 1;
}
return num;
}
protected double karakaLongitude (Body.Name b)
{
double lon = h.getPosition(b).longitude.toZodiacHouseOffset();
if (b == Body.Name.Rahu || b == Body.Name.Ketu)
lon = 30.0 - lon;
return lon;
}
protected Body.Name findAtmaKaraka ()
{
Body.Name[] karakaBodies =
{
Body.Name.Sun, Body.Name.Moon, Body.Name.Mars, Body.Name.Mercury,
Body.Name.Jupiter, Body.Name.Venus, Body.Name.Saturn, Body.Name.Rahu
};
double lon = 0.0;
Body.Name ret = Body.Name.Sun;
foreach (Body.Name bn in karakaBodies)
{
double offset = karakaLongitude (bn);
if (offset > lon) lon = offset;
ret = bn;
}
return ret;
}
public ArrayList findGrahasInHouse (ZodiacHouse.Name zh)
{
ArrayList ret = new ArrayList();
foreach (DivisionPosition dp in std_div_pos)
{
if (dp.type == BodyType.Name.Graha &&
dp.zodiac_house.value == zh)
{
ret.Add (dp.name);
}
}
return ret;
}
}
// Stronger rasi has larger number of grahas
// Stronger graha is in such a rasi
public class StrengthByConjunction : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByConjunction (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int numa = this.numGrahasInZodiacHouse (za);
int numb = this.numGrahasInZodiacHouse (zb);
if (numa > numb) return true;
if (numb > numa) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
return stronger (
h.getPosition(m).toDivisionPosition(dtype).zodiac_house.value,
h.getPosition(n).toDivisionPosition(dtype).zodiac_house.value
);
}
}
// Stronger rasi has larger number of grahas in kendras
// Stronger graha is in such a rasi
public class StrengthByKendraConjunction: BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByKendraConjunction (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public int value (ZodiacHouse.Name _zh)
{
int[] kendras = new int[4] {1, 4, 7, 10};
int numGrahas=0;
ZodiacHouse zh = new ZodiacHouse(_zh);
foreach (int i in kendras)
{
numGrahas += this.numGrahasInZodiacHouse(zh.add(i).value);
}
return numGrahas;
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int numa = value (za);
int numb = value (zb);
if (numa > numb) return true;
if (numb > numa) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
return stronger (
h.getPosition(m).toDivisionPosition(dtype).zodiac_house.value,
h.getPosition(n).toDivisionPosition(dtype).zodiac_house.value
);
}
}
// Stronger rasi is the first one
// Stronger graha is the first one
public class StrengthByFirst: BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByFirst (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
return true;
}
public bool stronger (Body.Name m, Body.Name n)
{
return true;
}
}
// Stronger rasi has larger number of exalted planets - debilitated planets
// Stronger planet is exalted or not debilitated
public class StrengthByExaltation : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByExaltation (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public int value (ZodiacHouse.Name zn)
{
int ret = 0;
foreach (DivisionPosition dp in std_div_pos)
{
if (dp.type != BodyType.Name.Graha) continue;
if (dp.zodiac_house.value != zn)continue;
if (dp.isExaltedPhalita()) ret++;
else if (dp.isDebilitatedPhalita()) ret--;
}
return ret;
}
public int value (Body.Name b)
{
if (h.getPosition(b).toDivisionPosition(dtype).isExaltedPhalita()) return 1;
else if (h.getPosition(b).toDivisionPosition(dtype).isDebilitatedPhalita()) return -1;
return 0;
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int vala = value (za);
int valb = value (zb);
if (vala > valb) return true;
if (valb > vala) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
int valm = value (m);
int valn = value (n);
if (valm > valn) return true;
if (valn > valm) return false;
throw new EqualStrength();
}
}
// Stronger rasi has more planets in moola trikona
// Stronger planet is in moola trikona rasi
public class StrengthByMoolaTrikona : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByMoolaTrikona (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public int value (ZodiacHouse.Name zn)
{
int ret = 0;
foreach (DivisionPosition dp in std_div_pos)
{
if (dp.type != BodyType.Name.Graha) continue;
if (dp.zodiac_house.value != zn)continue;
ret += value (dp.name);
}
return ret;
}
public int value (Body.Name b)
{
if (h.getPosition(b).toDivisionPosition(dtype).isInMoolaTrikona()) return 1;
return 0;
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int vala = value (za);
int valb = value (zb);
if (vala > valb) return true;
if (valb > vala) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
int valm = value (m);
int valn = value (n);
if (valm > valn) return true;
if (valn > valm) return false;
throw new EqualStrength();
}
}
// Stronger rasi has more planets in own house
// Stronger planet is in own house
public class StrengthByOwnHouse : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByOwnHouse (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public int value (ZodiacHouse.Name zn)
{
int ret = 0;
foreach (DivisionPosition dp in std_div_pos)
{
if (dp.type != BodyType.Name.Graha) continue;
if (dp.zodiac_house.value != zn)continue;
ret += value (dp.name);
}
return ret;
}
public int value (Body.Name b)
{
if (h.getPosition(b).toDivisionPosition(dtype).isInOwnHouse()) return 1;
return 0;
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int vala = value (za);
int valb = value (zb);
if (vala > valb) return true;
if (valb > vala) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
int valm = value (m);
int valn = value (n);
if (valm > valn) return true;
if (valn > valm) return false;
throw new EqualStrength();
}
}
// Stronger rasi has a graha which has traversed larger longitude
// Stronger graha has traversed larger longitude in its house
public class StrengthByLongitude : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByLongitude (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
Body.Name[] karakaBodies =
{
Body.Name.Sun, Body.Name.Moon, Body.Name.Mars, Body.Name.Mercury,
Body.Name.Jupiter, Body.Name.Venus, Body.Name.Saturn, Body.Name.Rahu
};
double lona = 0.0, lonb = 0.0;
foreach (Body.Name bn in karakaBodies)
{
DivisionPosition div = h.getPosition(bn).toDivisionPosition(new Division(Basics.DivisionType.Rasi));
double offset = karakaLongitude (bn);
if (div.zodiac_house.value == za && offset > lona)
lona = offset;
else if (div.zodiac_house.value == zb && offset > lonb)
lonb = offset;
}
if (lona > lonb) return true;
if (lonb > lona) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
double lonm = karakaLongitude (m);
double lonn = karakaLongitude (n);
if (lonm > lonn) return true;
if (lonn > lonm) return false;
throw new EqualStrength();
}
}
// Stronger rasi contains AK
// Stronger graha is AK
public class StrengthByAtmaKaraka : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByAtmaKaraka (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
ArrayList ala = findGrahasInHouse (za);
ArrayList alb = findGrahasInHouse (zb);
Body.Name ak = findAtmaKaraka();
foreach (Body.Name ba in ala)
{
if (ba == ak) return true;
}
foreach (Body.Name bb in alb)
{
if (bb == ak) return false;
}
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
Body.Name ak = findAtmaKaraka();
if (m == ak) return true;
if (n == ak) return false;
throw new EqualStrength();
}
}
// Stronger rasi's lord has traversed larger longitude
public class StrengthByLordsLongitude : BaseStrength, IStrengthRasi
{
public StrengthByLordsLongitude (Horoscope h, Division dtype, bool bSimpleLord)
: base (h, dtype, bSimpleLord) {}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
Body.Name lora = this.GetStrengthLord(za);
Body.Name lorb = this.GetStrengthLord(zb);
double offa = this.karakaLongitude(lora);
double offb = this.karakaLongitude(lorb);
if (offa > offb) return true;
if (offb > offa) return false;
throw new EqualStrength();
}
}
// Stronger rasi's lord is AK
public class StrengthByLordIsAtmaKaraka : BaseStrength, IStrengthRasi
{
public StrengthByLordIsAtmaKaraka (Horoscope h, Division dtype, bool bSimpleLord)
: base (h, dtype, bSimpleLord) {}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
Body.Name lora = this.GetStrengthLord(za);
Body.Name lorb = this.GetStrengthLord(zb);
Body.Name ak = findAtmaKaraka();
if (lora == ak) return true;
if (lorb == ak) return false;
throw new EqualStrength();
}
}
// Stronger rasi's lord by nature (moveable, fixed, dual)
// Stronger graha's dispositor in such a rasi
public class StrengthByLordsNature : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByLordsNature (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public int naturalValueForRasi (ZodiacHouse.Name zha)
{
Body.Name bl = h.LordOfZodiacHouse(zha, dtype);
ZodiacHouse.Name zhl = h.getPosition(bl).toDivisionPosition(dtype).zodiac_house.value;
int[] vals = new int[] {3,1,2}; // dual, move, fix
return vals[(int)zhl % 3];
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int[] vals = new int[] {3,1,2}; // dual, move, fix
int a = this.naturalValueForRasi(za);
int b = this.naturalValueForRasi(zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
ZodiacHouse.Name za = h.getPosition(m).toDivisionPosition(dtype).zodiac_house.value;
ZodiacHouse.Name zb = h.getPosition(n).toDivisionPosition(dtype).zodiac_house.value;
return stronger (za, zb);
}
}
// Stronger rasi by nature (moveable, fixed, dual)
// Stronger graha in such a rasi
public class StrengthByRasisNature : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByRasisNature (Horoscope h, Division dtype)
: base (h, dtype, true) {}
public int naturalValueForRasi (ZodiacHouse.Name zha)
{
int[] vals = new int[] {3,1,2}; // dual, move, fix
return vals[(int)zha % 3];
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int[] vals = new int[] {3,1,2}; // dual, move, fix
int a = this.naturalValueForRasi(za);
int b = this.naturalValueForRasi(zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
ZodiacHouse.Name za = h.getPosition(m).toDivisionPosition(dtype).zodiac_house.value;
ZodiacHouse.Name zb = h.getPosition(n).toDivisionPosition(dtype).zodiac_house.value;
return stronger (za, zb);
}
}
// Stronger rasi has its lord in a house of different oddity
// Stronger graha in such a rasi
public class StrengthByLordInDifferentOddity : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByLordInDifferentOddity (Horoscope h, Division dtype, bool bSimpleLord)
: base (h, dtype, bSimpleLord) {}
protected int oddityValueForZodiacHouse (ZodiacHouse.Name zh)
{
Body.Name lname = this.GetStrengthLord(zh);
BodyPosition lbpos = h.getPosition(lname);
DivisionPosition ldpos = h.CalculateDivisionPosition(lbpos, dtype);
ZodiacHouse zh_lor = ldpos.zodiac_house;
//System.Console.WriteLine(" DiffOddity {0} {1} {2}", zh.ToString(), zh_lor.value.ToString(), (int)zh %2==(int)zh_lor.value%2);
if ((int)zh % 2 == (int)zh_lor.value % 2)
return 0;
return 1;
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int a = this.oddityValueForZodiacHouse(za);
int b = this.oddityValueForZodiacHouse(zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name ba, Body.Name bb)
{
ZodiacHouse.Name za = h.getPosition(ba).toDivisionPosition(dtype).zodiac_house.value;
ZodiacHouse.Name zb = h.getPosition(bb).toDivisionPosition(dtype).zodiac_house.value;
return stronger (za, zb);
}
}
// Stronger rasi has more conjunctions/rasi drishtis of Jupiter, Mercury and Lord
// Stronger graha is in such a rasi
public class StrengthByAspectsRasi : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByAspectsRasi (Horoscope h, Division dtype, bool bSimpleLord)
: base (h, dtype, bSimpleLord) {}
protected int value (ZodiacHouse zj, ZodiacHouse zm, ZodiacHouse.Name zx)
{
int ret = 0;
ZodiacHouse zh = new ZodiacHouse(zx);
Body.Name bl = this.GetStrengthLord(zx);
ZodiacHouse zl = h.getPosition(bl).toDivisionPosition(dtype).zodiac_house;
if (zj.RasiDristi(zh) || zj.value == zh.value) ret++;
if (zm.RasiDristi(zh) || zm.value == zh.value) ret++;
if (zl.RasiDristi(zh) || zl.value == zh.value) ret++;
return ret;
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
ZodiacHouse zj = h.getPosition(Body.Name.Jupiter).toDivisionPosition(dtype).zodiac_house;
ZodiacHouse zm = h.getPosition(Body.Name.Mercury).toDivisionPosition(dtype).zodiac_house;
int a = this.value(zj, zm, za);
int b = this.value(zj, zm, zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
ZodiacHouse.Name zm = h.getPosition(m).toDivisionPosition(dtype).zodiac_house.value;
ZodiacHouse.Name zn = h.getPosition(n).toDivisionPosition(dtype).zodiac_house.value;
return stronger (zm, zn);
}
}
// Stronger rasi has its Lord in its house
// Stronger graha is in its own house
public class StrengthByLordInOwnHouse : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByLordInOwnHouse (Horoscope h, Division dtype, bool bSimpleLord)
: base (h, dtype, bSimpleLord) {}
protected int value (ZodiacHouse.Name _zh)
{
int ret=0;
ZodiacHouse zh = new ZodiacHouse(_zh);
Body.Name bl = this.GetStrengthLord(zh);
DivisionPosition pl = h.getPosition(bl).toDivisionPosition(dtype);
DivisionPosition pj = h.getPosition(Body.Name.Jupiter).toDivisionPosition(dtype);
DivisionPosition pm = h.getPosition(Body.Name.Mercury).toDivisionPosition(dtype);
if (pl.GrahaDristi(zh)) ret++;
if (pj.GrahaDristi(zh)) ret++;
if (pm.GrahaDristi(zh)) ret++;
return ret;
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int a = this.value(za);
int b = this.value(zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
ZodiacHouse.Name zm = h.getPosition(m).toDivisionPosition(dtype).zodiac_house.value;
ZodiacHouse.Name zn = h.getPosition(n).toDivisionPosition(dtype).zodiac_house.value;
return stronger (zm, zn);
}
}
public class StrengthByVimsottariDasaLength : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByVimsottariDasaLength (Horoscope h, Division dtype)
: base (h, dtype, false) {}
protected double value (ZodiacHouse.Name zh)
{
double length = 0;
foreach (BodyPosition bp in h.positionList)
{
if (bp.type == BodyType.Name.Graha)
length = Math.Max(length, VimsottariDasa.LengthOfDasa(bp.name));
}
return length;
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
double a = value (za);
double b = value (zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
double a = VimsottariDasa.LengthOfDasa(m);
double b = VimsottariDasa.LengthOfDasa(n);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
}
// Stronger graha has longer length
// Stronger rasi has a graha with longer length placed therein
public class StrengthByKarakaKendradiGrahaDasaLength : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByKarakaKendradiGrahaDasaLength (Horoscope h, Division dtype)
: base (h, dtype, false) { }
protected double value (ZodiacHouse.Name zh)
{
double length = 0;
foreach (BodyPosition bp in h.positionList)
{
if (bp.type == BodyType.Name.Graha)
{
DivisionPosition dp = bp.toDivisionPosition(dtype);
length = Math.Max(length, KarakaKendradiGrahaDasa.LengthOfDasa(h, dtype, bp.name, dp));
}
}
return length;
}
protected double value (Body.Name b)
{
DivisionPosition dp = h.getPosition(b).toDivisionPosition(dtype);
return KarakaKendradiGrahaDasa.LengthOfDasa(h, dtype, b, dp);
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
double a = value(za);
double b = value(zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
double a = value (m);
double b = value (n);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
}
// Stronger rasi has a larger narayana dasa length
// Stronger graha is in such a rasi
public class StrengthByNarayanaDasaLength : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByNarayanaDasaLength (Horoscope h, Division dtype, bool bSimpleLord)
: base (h, dtype, bSimpleLord) {}
protected int value (ZodiacHouse.Name _zh)
{
Body.Name bl = this.GetStrengthLord(_zh);
DivisionPosition pl = h.getPosition(bl).toDivisionPosition(dtype);
return NarayanaDasa.NarayanaDasaLength (new ZodiacHouse(_zh), pl);
}
protected int value (Body.Name bm)
{
ZodiacHouse.Name zm = h.getPosition(bm).toDivisionPosition(dtype).zodiac_house.value;
return value(zm);
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int a = this.value(za);
int b = this.value(zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
int a = this.value(m);
int b = this.value(n);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
}
// Stronger rasi has more graha drishtis of Jupiter, Mercury and Lord
// Stronger graha is in such a rasi
public class StrengthByAspectsGraha : BaseStrength, IStrengthRasi, IStrengthGraha
{
public StrengthByAspectsGraha (Horoscope h, Division dtype, bool bSimpleLord)
: base (h, dtype, bSimpleLord) {}
protected int value (ZodiacHouse.Name _zh)
{
int val = 0;
Body.Name bl = this.GetStrengthLord(_zh);
DivisionPosition dl = h.getPosition(bl).toDivisionPosition(dtype);
DivisionPosition dj = h.getPosition(Body.Name.Jupiter).toDivisionPosition(dtype);
DivisionPosition dm = h.getPosition(Body.Name.Mercury).toDivisionPosition(dtype);
ZodiacHouse zh = new ZodiacHouse(_zh);
if (dl.GrahaDristi(zh) || dl.zodiac_house.value == _zh) val++;
if (dj.GrahaDristi(zh) || dj.zodiac_house.value == _zh) val++;
if (dm.GrahaDristi(zh) || dm.zodiac_house.value == _zh) val++;
return val;
}
protected int value (Body.Name bm)
{
return value (h.getPosition(bm).toDivisionPosition(dtype).zodiac_house.value);
}
public bool stronger (ZodiacHouse.Name za, ZodiacHouse.Name zb)
{
int a = this.value(za);
int b = this.value(zb);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
public bool stronger (Body.Name m, Body.Name n)
{
int a = this.value(m);
int b = this.value(n);
if (a > b) return true;
if (a < b) return false;
throw new EqualStrength();
}
}
public class FindStronger
{
Horoscope h;
Division dtype;
ArrayList rules;
bool bUseSimpleLords;
public FindStronger (Horoscope _h, Division _dtype, ArrayList _rules, bool _UseSimpleLords)
{
h = _h;
dtype = _dtype;
rules = _rules;
bUseSimpleLords = _UseSimpleLords;
}
public FindStronger (Horoscope _h, Division _dtype, ArrayList _rules)
{
h = _h;
dtype = _dtype;
rules = _rules;
bUseSimpleLords = false;
}
static private StrengthOptions GetStrengthOptions (Horoscope h)
{
if (h.strength_options == null)
return MhoraGlobalOptions.Instance.SOptions;
else
return h.strength_options;
}
static public ArrayList RulesNaisargikaDasaRasi (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).NaisargikaDasaRasi);
}
static public ArrayList RulesNarayanaDasaRasi (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).NarayanaDasaRasi);
}
static public ArrayList RulesKarakaKendradiGrahaDasaRasi (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).KarakaKendradiGrahaDasaRasi);
}
static public ArrayList RulesKarakaKendradiGrahaDasaGraha (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).KarakaKendradiGrahaDasaGraha);
}
static public ArrayList RulesKarakaKendradiGrahaDasaColord (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).KarakaKendradiGrahaDasaColord);
}
static public ArrayList RulesMoolaDasaRasi (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).MoolaDasaRasi);
}
static public ArrayList RulesNavamsaDasaRasi (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).NavamsaDasaRasi);
}
static public ArrayList RulesJaiminiFirstRasi (Horoscope h)
{
ArrayList Rules = new ArrayList();
Rules.Add(ERasiStrength.AtmaKaraka);
Rules.Add(ERasiStrength.Conjunction);
Rules.Add(ERasiStrength.Exaltation);
Rules.Add(ERasiStrength.MoolaTrikona);
Rules.Add(ERasiStrength.OwnHouse);
Rules.Add(ERasiStrength.RasisNature);
Rules.Add(ERasiStrength.LordIsAtmaKaraka);
Rules.Add(ERasiStrength.LordsLongitude);
Rules.Add(ERasiStrength.LordInDifferentOddity);
return Rules;
}
static public ArrayList RulesJaiminiSecondRasi (Horoscope h)
{
ArrayList Rules = new ArrayList();
Rules.Add(ERasiStrength.AspectsRasi);
return Rules;
}
static public ArrayList RulesNaisargikaDasaGraha (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).NaisargikaDasaGraha);
}
static public ArrayList RulesVimsottariGraha (Horoscope h)
{
ArrayList Rules = new ArrayList();
Rules.Add(EGrahaStrength.KendraConjunction);
Rules.Add(EGrahaStrength.First);
return Rules;
}
static public ArrayList RulesStrongerCoLord (Horoscope h)
{
return new ArrayList(FindStronger.GetStrengthOptions(h).Colord);
}
public OrderedZodiacHouses[] ResultsZodiacKendras (ZodiacHouse.Name _zh)
{
OrderedZodiacHouses[] zRet = new OrderedZodiacHouses[3];
ZodiacHouse zh = new ZodiacHouse(_zh);
ZodiacHouse.Name[] zh1 = new ZodiacHouse.Name[4] { zh.add(1).value, zh.add(4).value, zh.add(7).value, zh.add(10).value };
ZodiacHouse.Name[] zh2 = new ZodiacHouse.Name[4] { zh.add(2).value, zh.add(5).value, zh.add(8).value, zh.add(11).value };
ZodiacHouse.Name[] zh3 = new ZodiacHouse.Name[4] { zh.add(3).value, zh.add(6).value, zh.add(9).value, zh.add(12).value };
zRet[0] = this.getOrderedHouses(zh1);
zRet[1] = this.getOrderedHouses(zh2);
zRet[2] = this.getOrderedHouses(zh3);
return zRet;
}
public ZodiacHouse.Name [] ResultsKendraRasis(ZodiacHouse.Name _zh)
{
ZodiacHouse.Name[] zRet = new ZodiacHouse.Name[12];
ZodiacHouse zh = new ZodiacHouse(_zh);
ZodiacHouse.Name[] zh1 = new ZodiacHouse.Name[4] { zh.add(1).value, zh.add(4).value, zh.add(7).value, zh.add(10).value };
ZodiacHouse.Name[] zh2 = new ZodiacHouse.Name[4] { zh.add(2).value, zh.add(5).value, zh.add(8).value, zh.add(11).value };
ZodiacHouse.Name[] zh3 = new ZodiacHouse.Name[4] { zh.add(3).value, zh.add(6).value, zh.add(9).value, zh.add(12).value };
getOrderedRasis(zh1).CopyTo(zRet, 0);
getOrderedRasis(zh2).CopyTo(zRet, 4);
getOrderedRasis(zh3).CopyTo(zRet, 8);
return zRet;
}
public ZodiacHouse.Name[] ResultsFirstSeventhRasis ()
{
ZodiacHouse.Name[] zRet = new ZodiacHouse.Name[12];
getOrderedRasis(new ZodiacHouse.Name[]{ZodiacHouse.Name.Ari, ZodiacHouse.Name.Lib}).CopyTo(zRet, 0);
getOrderedRasis(new ZodiacHouse.Name[]{ZodiacHouse.Name.Tau, ZodiacHouse.Name.Sco}).CopyTo(zRet, 2);
getOrderedRasis(new ZodiacHouse.Name[]{ZodiacHouse.Name.Gem, ZodiacHouse.Name.Sag}).CopyTo(zRet, 4);
getOrderedRasis(new ZodiacHouse.Name[]{ZodiacHouse.Name.Can, ZodiacHouse.Name.Cap}).CopyTo(zRet, 6);
getOrderedRasis(new ZodiacHouse.Name[]{ZodiacHouse.Name.Leo, ZodiacHouse.Name.Aqu}).CopyTo(zRet, 8);
getOrderedRasis(new ZodiacHouse.Name[]{ZodiacHouse.Name.Vir, ZodiacHouse.Name.Pis}).CopyTo(zRet, 10);
return zRet;
}
public Body.Name[] getOrderedGrahas ()
{
Body.Name[] grahas = new Body.Name[]
{
Body.Name.Sun, Body.Name.Moon, Body.Name.Mars, Body.Name.Mercury,
Body.Name.Jupiter, Body.Name.Venus, Body.Name.Saturn,
Body.Name.Rahu, Body.Name.Ketu
};
return getOrderedGrahas (grahas);
}
public Body.Name[] getOrderedGrahas (Body.Name[] grahas)
{
if (grahas.Length <= 1)
return grahas;
for (int i=0; i<grahas.Length-1; i++)
{
for (int j=0; j<grahas.Length-1; j++)
{
if (false == this.CmpGraha(grahas[j], grahas[j+1], false))
{
Body.Name temp = grahas[j];
grahas[j] = grahas[j+1];
grahas[j+1] = temp;
}
}
}
return grahas;
}
public ZodiacHouse.Name[] getOrderedRasis ()
{
ZodiacHouse.Name[] rasis = new ZodiacHouse.Name[]
{
ZodiacHouse.Name.Ari, ZodiacHouse.Name.Tau, ZodiacHouse.Name.Gem,
ZodiacHouse.Name.Can, ZodiacHouse.Name.Leo, ZodiacHouse.Name.Vir,
ZodiacHouse.Name.Lib, ZodiacHouse.Name.Sco, ZodiacHouse.Name.Sag,
ZodiacHouse.Name.Cap, ZodiacHouse.Name.Aqu, ZodiacHouse.Name.Pis
};
return getOrderedRasis (rasis);
}
public OrderedZodiacHouses getOrderedHouses (ZodiacHouse.Name[] rasis)
{
ZodiacHouse.Name[] zh_ordered = getOrderedRasis(rasis);
OrderedZodiacHouses oz = new OrderedZodiacHouses();
foreach (ZodiacHouse.Name zn in zh_ordered)
oz.houses.Add(zn);
return oz;
}
public ZodiacHouse.Name[] getOrderedRasis (ZodiacHouse.Name[] rasis)
{
if (rasis.Length < 2) return rasis;
int length = rasis.Length;
for (int i=0; i<length; i++)
{
for (int j=0; j<length-1; j++)
{
//System.Console.WriteLine ("Comparing {0} and {1}", i, j);
if (false == this.CmpRasi(rasis[j], rasis[j+1], false))
{
ZodiacHouse.Name temp = rasis[j];
rasis[j] = rasis[j+1];
rasis[j+1] = temp;
}
}
}
return rasis;
}
public ZodiacHouse.Name StrongerRasi (ZodiacHouse.Name za, ZodiacHouse.Name zb, bool bSimpleLord, ref int winner)
{
if (CmpRasi (za, zb, bSimpleLord, ref winner)) return za;
return zb;
}
public ZodiacHouse.Name StrongerRasi (ZodiacHouse.Name za, ZodiacHouse.Name zb, bool bSimpleLord)
{
int winner = 0;
return StrongerRasi(za, zb, bSimpleLord, ref winner);
}