易经计算同根分值的算法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dz
{
//易经计算同根分值部分算法
class Program
{
static void Main(string[] args)
{
float[] dzlist = new float[5];
dzlist[0] = 10;
dzlist[1] = 30;
dzlist[2] = 0;
dzlist[3] = 10;
dzlist[4] = 40;

int index=4;
System.Console.WriteLine(tgfe(dzlist, index));
System.Console.ReadKey();
}

public static float tgfe(float[] tglist, int index)
{
float sum = 0;
for (int i = 0; i < tglist.Length; i++) {
if (tglist[i] == 0) continue;
if (i == index) {
sum = sum + tglist[index]; continue;
}
else if (i < index) {
int l = i; int r = index;
for (int j = i; j <=index; j++) {
if (tglist[j] == 0) {
if (j == 0) l = 0;
else l = j-1;
break;
} else {
l = j;
};
}
for (int j = index; j > l; j--)
{
if (tglist[j] == 0)
{
if (j == tglist.Length - 1) r = tglist.Length - 1;
else if (j == index)
{
r = index;
}
else r = j + 1; break;
}
else
{
r = j;
}
}
switch (r - l) {
case 0:
sum = sum + tglist[i] * 1F;
break;
case 1: sum = sum + tglist[i] * 0.9F; break;
case 2: sum = sum + tglist[i] * 0.75F; break;
case 3: sum = sum + tglist[i] * 0.65F; break;
case 4: sum = sum + tglist[i] * 0.6F; break;
default: break;
}
}
else if (i > index) {
int l = index; int r = i;
for (int j = index; j <= i; j++)
{
if (tglist[j] == 0)
{
if (j == 0) l = 0;
else l = j - 1;
break;
}
else
{
l = j;
};
}
for (int j = i; j > l; j--)
{
if (tglist[j] == 0)
{
if (j == tglist.Length - 1) r = tglist.Length - 1;
else if (j == index)
{
r = index;
}
else r = j + 1; break;
}
else
{
r = j;
}
}
switch (r - l)
{
case 0:
sum = sum + tglist[i] * 1F;
break;
case 1: sum = sum + tglist[i] * 0.9F; break;
case 2: sum = sum + tglist[i] * 0.75F; break;
case 3: sum = sum + tglist[i] * 0.65F; break;
case 4: sum = sum + tglist[i] * 0.6F; break;
default: break;
}

}

}

return sum;
}
}
}

posted on 2013-11-21 13:59  刀锋诚心  阅读(341)  评论(0编辑  收藏  举报